Received: by 10.192.165.156 with SMTP id m28csp182155imm; Thu, 12 Apr 2018 19:33:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx482bqsJ2rPuKEZsBJSc0YrJpWKh4kBpRsPh7ksmI4wf5RkMAtLo2jiyKvRHXAsbpTlkPcb6 X-Received: by 10.101.77.145 with SMTP id p17mr2583529pgq.275.1523586814871; Thu, 12 Apr 2018 19:33:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523586814; cv=none; d=google.com; s=arc-20160816; b=b8jFX7Xl7LoawzSMEkHwx4uvjJgkgOklsQaa+9O+4Daz80bYjLTTChYkK7SDk1WY08 RKlNTAn5SqKf+FUefhDPq0UZjJGu2wfIjdg/TJwo3po2mPRN9QoR46ZUZTU98bUjgo4U 86Z5/M1064jhs09Smx1d0tKBiKj0P1vvl46RbFX8w75d0RgNFkodtazKjhY4tzEmvaTE rYxSw0qhlzegLDLMGZkiZG4i053+Pgs7izpNKGnkxW+VCM9oKPqywFWzeeo6vj89kXWx 4C3jJcXIlH1yQpqgSHmXSKl7MF/7OuSGQyrVOAbh7lJjiVEbOZ699ZmP8VyLmJ10dSBb rxuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :in-reply-to:subject:cc:to:user-agent:organization:from:date :message-id:content-transfer-encoding:mime-version:dkim-signature :dkim-filter:arc-authentication-results; bh=KrCMdFWZSDXfhO2oddw/mRT6zJbpQvzrzpsV3UwfKY4=; b=VgggsuTqCZ9X2OXIFRk7GuitJ3eztzck3Cwjw99Tn+6wPv7yX1/Z08VXpd+DOF9dyV d4cztb18O3VXu4KDRrd85BG4556Lj7j24wLbLQb/jisHZg44NpE8qi4zrDxcN7JE/DBA LXIkhxnnwcn8k36trftceWH1CT2glC8m9jX4AOyAuXniKoG5SMZOgDyAzSGs6wnf255S Rcu13fyby1dL9rPjeK3agZIcnd9ZjgPG6PKcjm9qNulPH4tweblCbeJ+Rb7yBub7d68H kvik2r+Pz9TcLnq+g5V3WiD5uYktHqvDxNll47HqzLlf8oHbunabLu5cbfga5t8cKlr+ lpRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Gv8V9th5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y2si3083416pgv.246.2018.04.12.19.33.21; Thu, 12 Apr 2018 19:33:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Gv8V9th5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753363AbeDMCcQ (ORCPT + 99 others); Thu, 12 Apr 2018 22:32:16 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:48899 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752594AbeDMCcO (ORCPT ); Thu, 12 Apr 2018 22:32:14 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20180413023211epoutp034755ac6bb6c6e9bd33dc44a047b7a818~k3g9lqx9t0314603146epoutp03j; Fri, 13 Apr 2018 02:32:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20180413023211epoutp034755ac6bb6c6e9bd33dc44a047b7a818~k3g9lqx9t0314603146epoutp03j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1523586731; bh=KrCMdFWZSDXfhO2oddw/mRT6zJbpQvzrzpsV3UwfKY4=; h=Date:From:To:Cc:Subject:In-reply-to:References:From; b=Gv8V9th5trdj5sIlEHOJQA6AP6xWUTUaGARSn3B+VhQKdEO4WLdeMIEFNhWR4jkix bvqEixQalqhWikl5qkKSQEQ0n410C9oWlrWxpJOOZrpGeoG238mHWavMOXj9W0309D QMWi/SYjsNmdZM5S8l0WpmV8oyp3pHHOSRo6MoEQ= Received: from epsmges1p2.samsung.com (unknown [182.195.40.69]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20180413023211epcas1p218ed158d5440ce64667de5ec07cba350~k3g9K-DZC2594425944epcas1p2Q; Fri, 13 Apr 2018 02:32:11 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 7C.BB.04034.F0610DA5; Fri, 13 Apr 2018 11:29:35 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20180413022934epcas1p3b4cbf4b7e86f81e590e4755436afd4f1~k3ergGO0i0458104581epcas1p3n; Fri, 13 Apr 2018 02:29:34 +0000 (GMT) X-AuditID: b6c32a36-f57ff70000000fc2-63-5ad0160f88e9 Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id F5.C8.03849.E0610DA5; Fri, 13 Apr 2018 11:29:34 +0900 (KST) MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset="utf-8" Received: from [10.113.63.77] by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P7300IRWQXA4C60@mmp1.samsung.com>; Fri, 13 Apr 2018 11:29:34 +0900 (KST) Message-id: <5AD0160E.7050601@samsung.com> Date: Fri, 13 Apr 2018 11:29:34 +0900 From: Chanwoo Choi Organization: Samsung Electronics User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 To: arvindY , myungjoo.ham@samsung.com, kyungmin.park@samsung.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH] PM / devfreq: use put_device() instead of kfree() In-reply-to: <5AD012CB.7030003@gmail.com> X-Brightmail-Tracker: H4sIAAAAAAAAA01Sa0hTYRjm29nlKC1P89LboponAxWcnqPTGS4qRQZZCBGYUXbSDxV3a2dK 1o9MKmu18BIIy2v1Q1ZiyZRSMpiWf8qi8BKlhJZkihCaWdnlbMfIf8/78Dzf870PL0mopmVq stjiwHYLZ6LlwdLu/pj4uJCIl7kJ3qUI/YirldA/r5xT6F/3NMj1C64BpH97rk2+W2Z86B5X GK95Pci40Lk1m8jFaUWYK8B2DbbkWwuKLYUGet/BvPQ8XXICE8ek6lNojYUzYwOdkZUdl1ls EiJpTRlnKhWobI7n6fhdaXZrqQNriqy8w0AfYRhWyySkaFmW1SYlHt3J6gTJcVzkm2RsK5tO tQ+3SCrQWJgTBZFAJYHrXLPCiYJJFfUAQfX87OrwDcFgV6f8n+p2zX2FH6uoXgTf58r9WElt gOW6CakTkSRBbYOBVyV+mqBi4NNirVR8ZxxBZd+KTNTHQuPiR+THUmoHNN3xEn4sF/jHn8YC WSFUJAwvTwU04VQOPGxeCuSGUceg2lcrEQN2Qs/ktYAmlMqE5XFXwBskBI++/RVYAKg2OXja 55G4QAZ0Nz6ViTgUPg96Ff5PA7UZXj0xiPoqBFWPmghxuI5gaHRCIhoSYbrVuZq8Hua/XpWJ ZiVcuqgSJUaYbnpHiHgPVLS3rrZYK4F77vOSarTVvaYw9//C3GsKa0GEB0VgG28uxDxjY7U8 Z+ZLLYXafKu5EwVuLDb5Abo5lOVDFInodUpN+YtclYwr48vNPgQkQYc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f81e590e4755436afd4f1 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20180330114418epcas5p1affd1c3d97e7422dd33e6d3ca73073be X-RootMTR: 20180330114418epcas5p1affd1c3d97e7422dd33e6d3ca73073be References: <5AD001C5.2040406@samsung.com> <5AD0041D.2050506@samsung.com> <5AD012CB.7030003@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018년 04월 13일 11:15, arvindY wrote: > Hi Chanwoo, > > On Friday 13 April 2018 06:43 AM, Chanwoo Choi wrote: >> On 2018년 04월 13일 10:03, Chanwoo Choi wrote: >>> Hi, >>> >>> I'm sorry for the late reply. >>> >>> On 2018년 03월 30일 20:44, Arvind Yadav wrote: >>>> Never directly free @dev after calling device_register() or >>>> device_unregister(), even if device_register() returned an error. >>>> Always use put_device() to give up the reference initialized. >>>> >>>> Signed-off-by: Arvind Yadav >>>> --- >>>> drivers/devfreq/devfreq.c | 4 +++- >>>> 1 file changed, 3 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c >>>> index fe2af6a..a225b94 100644 >>>> --- a/drivers/devfreq/devfreq.c >>>> +++ b/drivers/devfreq/devfreq.c >>>> @@ -625,7 +625,8 @@ struct devfreq *devfreq_add_device(struct device *dev, >>>> err = device_register(&devfreq->dev); >>>> if (err) { >>>> mutex_unlock(&devfreq->lock); >>>> - goto err_dev; >>>> + put_device(&devfreq->dev); >>>> + goto err_out; >>> why do you change the goto postion? >>> err_out is correct to free the memory of devfreq instance. >> Sorry. err_dev is correct instead of err_out. > > If you will see the comment for device_register(drivers/base/core.c) > there is mentioned that 'NOTE: _Never_ directly free @dev > after calling this function, even if it returned an error! > Always use put_device() to give up the reference initialized > in this function instead. Here put_device() will decrement > the last reference and then free the memory by calling dev->release. > Internally put_device() -> kobject_put() -> kobject_cleanup() which > is responsible to call 'dev -> release' and also free other kobject resources. > > We are releasing devfreq in devfreq_dev_release(). So no need > to call kfree() again. It'll be redundant. 'err_out' is correct. You're right. err_out is correct. put_device() -> dev->release() -> devfreq_dev_release() -> kfree(devfreq) >> >>>> } >>>> devfreq->trans_table = devm_kzalloc(&devfreq->dev, >>>> @@ -671,6 +672,7 @@ struct devfreq *devfreq_add_device(struct device *dev, >>>> mutex_unlock(&devfreq_list_lock); >>>> device_unregister(&devfreq->dev); >>>> + devfreq = NULL; >>> It is wrong. If you initialize the devfreq as NULL, >>> never free the 'devfreq' instance. > > No need to release memory after device_unregister(). > driver core will take care of this. It will release memory > So no need to call free again. If you have to initialize the devfreq instance as NULL, I think that you better to init in the devfreq_dev_release() as following: diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index fe2af6aa88fc..8c52a13d3887 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -543,6 +543,7 @@ static void devfreq_dev_release(struct device *dev) mutex_destroy(&devfreq->lock); kfree(devfreq); + devfreq = NULL; } >>> >>>> err_dev: >>>> if (devfreq) >>>> kfree(devfreq); >>>> >>> >> > > ~arvind > > > -- Best Regards, Chanwoo Choi Samsung Electronics