Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751380AbdHXBnO (ORCPT ); Wed, 23 Aug 2017 21:43:14 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:20003 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751026AbdHXBnB (ORCPT ); Wed, 23 Aug 2017 21:43:01 -0400 X-AuditID: b6c32a47-f79db6d000003732-ba-599e2f233bdd From: Chanwoo Choi To: myungjoo.ham@samsung.com, kyungmin.park@samsung.com, cw00.choi@samsung.com Cc: rafael.j.wysocki@intel.com, chanwoo@kernel.org, inki.dae@samsung.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 01/12] PM / devfreq: Fix memory leak when fail to register device Date: Thu, 24 Aug 2017 10:42:48 +0900 Message-id: <1503538979-22693-2-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1503538979-22693-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLKsWRmVeSWpSXmKPExsWy7bCmha6y/rxIg/5uPYuJN66wWFz/8pzV YtL9CSwWZ5vesFtc3jWHzeJz7xFGi9uNK9gsHq94y26xYOMjRgdOj8V7XjJ5bFrVyebRt2UV o8fnTXIBLFGpNhmpiSmpRQqpecn5KZl56bZK3sHxzvGmZgaGuoaWFuZKCnmJuam2Si4+Abpu mTlAtygplCXmlAKFAhKLi5X07WyK8ktLUhUy8otLbJWiDQ2N9AwNzPWMjIz0TIxjrYxMgUoS UjNmfWplL1jKVbF7/hGmBsazHF2MnBwSAiYS93r2sUHYYhIX7q0Hsrk4hAR2MEosXNbHCOF8 Z5TouHeSHaZj3+oDUFUbGCVWnmhihnB+MEqcmLCJEaSKTUBLYv+LG2BzRQQCJDrXrmICKWIW mMMocWbzfhaQhLBAsMSUw0tZQWwWAVWJWf/3gDXzCrhK/G7ayAKxTk7iw55HYKs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INjOuOVSsycKxfcPMXq2Fu5bEvd2WuX/YvCgiJ5e/MuJFmwXVk yZnSHX3zbze1d7Psz138NCdgT0dtv1Se5JQNqUy9whU69pPjb8666vPostKOEw/ftHAEPzdd 98Y/1Vtgfe692NOs3959ZZ2l/syhrbonN0Il/CWTXWPyn2vBTnlfX2bozHxrpsRSnJFoqMVc VJwIAPBHxuIlAgAA X-CMS-MailID: 20170824014259epcas2p398a53a9a76d9aff7e35cf8515ec4e46a X-Msg-Generator: CA X-Sender-IP: 182.195.42.143 X-Local-Sender: =?UTF-8?B?7LWc7LCs7JqwG1RpemVuIFBsYXRmb3JtIExhYihTL1fshLw=?= =?UTF-8?B?7YSwKRvsgrzshLHsoITsnpAbU2VuaW9yIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?Q2hhbndvbyBDaG9pG1RpemVuIFBsYXRmb3JtIExhYi4bU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtTZW5pb3IgRW5naW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG1RFTEUbQzEwVjgxMTE=?= CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20170824014259epcas2p398a53a9a76d9aff7e35cf8515ec4e46a X-RootMTR: 20170824014259epcas2p398a53a9a76d9aff7e35cf8515ec4e46a References: <1503538979-22693-1-git-send-email-cw00.choi@samsung.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1276 Lines: 39 When the devfreq_add_device fails to register deivce, the memory leak of devfreq instance happen. So, this patch fix the memory leak issue. Before freeing the devfreq instance checks whether devfreq instance is NULL or not because the device_unregister() frees the devfreq instance when jumping to the 'err_init'. It is to prevent the duplicate the kfee(devfreq). Cc: stable@vger.kernel.org Fixes: ac4b281176a5 ("PM / devfreq: fix duplicated kfree on devfreq pointer") Signed-off-by: Chanwoo Choi --- drivers/devfreq/devfreq.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index dea04871b50d..a1c4ee818614 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -564,7 +564,7 @@ struct devfreq *devfreq_add_device(struct device *dev, err = device_register(&devfreq->dev); if (err) { mutex_unlock(&devfreq->lock); - goto err_out; + goto err_dev; } devfreq->trans_table = devm_kzalloc(&devfreq->dev, @@ -610,6 +610,9 @@ struct devfreq *devfreq_add_device(struct device *dev, mutex_unlock(&devfreq_list_lock); device_unregister(&devfreq->dev); +err_dev: + if (devfreq) + kfree(devfreq); err_out: return ERR_PTR(err); } -- 1.9.1