From patchwork Thu Aug 24 01:42:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 9918849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BDEF9603FA for ; Thu, 24 Aug 2017 01:43:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B288C28AE1 for ; Thu, 24 Aug 2017 01:43:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A233128ADA; Thu, 24 Aug 2017 01:43:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE1DE28ADF for ; Thu, 24 Aug 2017 01:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751094AbdHXBnL (ORCPT ); Wed, 23 Aug 2017 21:43:11 -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 Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20170824014300epoutp010a2874f8dc03ce0e81752d180beccfc9~dpLx9Je2C0604506045epoutp01g; Thu, 24 Aug 2017 01:43:00 +0000 (GMT) Received: from epsmges2p3.samsung.com (unknown [182.195.40.69]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20170824014259epcas1p234812584fec3d8dfa5910ad5a87c9faf~dpLxsbtyg0456704567epcas1p2r; Thu, 24 Aug 2017 01:42:59 +0000 (GMT) Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p3.samsung.com (Symantec Messaging Gateway) with SMTP id C6.EC.14130.32F2E995; Thu, 24 Aug 2017 10:42:59 +0900 (KST) Received: from epsmgms2p2new.samsung.com (unknown [182.195.42.143]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20170824014259epcas2p398a53a9a76d9aff7e35cf8515ec4e46a~dpLxLwk3Z0705507055epcas2p3v; Thu, 24 Aug 2017 01:42:59 +0000 (GMT) X-AuditID: b6c32a47-f79db6d000003732-ba-599e2f233bdd Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 1A.38.10338.32F2E995; Thu, 24 Aug 2017 10:42:59 +0900 (KST) Received: from localhost.localdomain ([10.113.62.212]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OV600BON23MQ710@mmp2.samsung.com>; Thu, 24 Aug 2017 10:42:59 +0900 (KST) 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 YtL9CSwWZ5vesFtc3jWHzeJz7xF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2PGB04PRbvecnksWlVJ5tH35ZV jB6fN8kFsERx2aSk5mSWpRbp2yVwZcz61MpesJSrYvf8I0wNjGc5uhg5OSQETCT2rT7A1sXI xSEksI5R4smjvywQzg9GiR3H17GDVLEJaEnsf3GDDcQWEfCT2D5/PSNIEbPALEaJI3f+gSWE BYIlphxeygpiswioSsz6v4cRxOYVcJX43bSRBWKdnMSHPY/AhnIKuEm0PO0CiwsB1ezpO8o4 gZFnASPDKkbJ1ILi3PTcYqMCo7zUcr3ixNzi0rx0veT83E2MwJDadlirfwfj4yXxhxgFOBiV eHgvLJwbKcSaWFZcmXuIUYKDWUmEd6/6vEgh3pTEyqrUovz4otKc1OJDjNIcLErivJl9MyKF BNITS1KzU1MLUotgskwcnFINjOuOVSsycKxfcPMXq2Fu5bEvd2WuX/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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-By: MyungJoo Ham. --- 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); }