Received: by 10.192.165.156 with SMTP id m28csp237351imm; Thu, 12 Apr 2018 20:58:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx49e4tyGKbNuz1NzMc4RoBEt7OLpnq4/HY4I7hkmAxrUu07RrgfVIhp3oHlRIlfX/JgKkM/C X-Received: by 10.98.32.80 with SMTP id g77mr10052614pfg.216.1523591938278; Thu, 12 Apr 2018 20:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523591938; cv=none; d=google.com; s=arc-20160816; b=xLeELTiwqaKaOnZ29nVD+W3Fd9f0AHYNs6MZqppFES0zRuEtztuRaOt73PvYSu734V nSNCr4eNNYtpMvGGd3ke/aJ+n6eCyz8s3c+aJ5fg9s1IOaA+G2Vcmg9RSzWJIIyzVW5B Sv7i+gSM2C0dP4NY8QXLHbg4KJXkwVCueb+qUmrIJZtU5seqVSOVEJ2P4AinmwYC1oxK HoTRHtTILxvtF4wkCenxPWPBHyawcC6bT4FbHh9SVubjHMVs//4FEzGd4fQL9Y6rARg9 L2hF+NQf50lqIcHze9B/bRUtIhk1zbwv0s1mdfIzls2nny0nnX+6LWVWIOCyiKxeox7+ oedg== 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=arQHTi1fFfUN8/bID2m1Mr8Fwi0IzIYLo5Zb+GPsyuo=; b=jl63hII+X8X+dJT3bY1muj3Utgk4U1J8LNoxkidPrqC/hwU1HlntJcX83KeF7bXyJ8 4TIBvDjM8utouB6ua7RwK7hVCVG7Y6q2FHbS7Alu5NXnYJS9VSx+lOFkfUnbzZDQXgiV E3TeYJSGGDpIFIc8vl/jVXVyRUEwSWerSA8+m1uJtsd09FkTmBNbC+zikFbwGexz/uUl +XyAe/chgTsT45lTLRdxYptvqV6ldeJ6+3YHKX3kRbpGoObrg5cUHic6zEApvopmj+90 bj2FbqRmz8lbWgRtSlMCIV/UyGiySOQoinUhzJGFzUeORWFGf5XPor25KilPuY0VMP8K owqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=BuPvACiq; 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 u9-v6si4812787plr.399.2018.04.12.20.58.42; Thu, 12 Apr 2018 20:58:58 -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=BuPvACiq; 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 S1753446AbeDMCnR (ORCPT + 99 others); Thu, 12 Apr 2018 22:43:17 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:26858 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753356AbeDMCnP (ORCPT ); Thu, 12 Apr 2018 22:43:15 -0400 Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20180413024313epoutp010987571cd7f2aefb47444a9a9fe97114~k3qmD1zTB2342323423epoutp01J; Fri, 13 Apr 2018 02:43:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20180413024313epoutp010987571cd7f2aefb47444a9a9fe97114~k3qmD1zTB2342323423epoutp01J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1523587393; bh=arQHTi1fFfUN8/bID2m1Mr8Fwi0IzIYLo5Zb+GPsyuo=; h=Date:From:To:Cc:Subject:In-reply-to:References:From; b=BuPvACiqoF07bKm8RKPd4zGg9IHLTpBexfGfxgUZS+zBPlYWJByj1D09TvNexR3eJ ahNZkjK0G4aGbdr95wuxaCCC/XcWvKYnoba2XPy40zdvvF9ok1SYtllcZXhkWDa/DY ETAQrTXwCknZjGntVaw2LRM3FRyaH1X8KFrdu6hs= Received: from epsmges1p1.samsung.com (unknown [182.195.40.68]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20180413024312epcas1p22b6d4320ec2839c37ddb4bd662d1f3b0~k3qlf3HRT0286902869epcas1p2M; Fri, 13 Apr 2018 02:43:12 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 2E.C0.04078.83910DA5; Fri, 13 Apr 2018 11:43:04 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20180413024303epcas1p17d208c9d813656e1cc6674e5d52abafb~k3qdDGfRM2206422064epcas1p1K; Fri, 13 Apr 2018 02:43:03 +0000 (GMT) X-AuditID: b6c32a35-151ff70000000fee-68-5ad01938f4a2 Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 52.0A.03849.73910DA5; Fri, 13 Apr 2018 11:43:03 +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 <0P7300JW8RJRYQ70@mmp1.samsung.com>; Fri, 13 Apr 2018 11:43:03 +0900 (KST) Message-id: <5AD01937.1070504@samsung.com> Date: Fri, 13 Apr 2018 11:43:03 +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: <5AD017E8.7020901@gmail.com> X-Brightmail-Tracker: H4sIAAAAAAAAA01SbUhTURjm7M7taq5uU+toZfOGkILTO7+upmYktkxICCwUWxe9bOI+ZHcz DRGTyhhqpma00tyPSPwIJlJ+FOZURmHOFpagM9L8aKQ/ssyf3e0q+e85z3me87zn4UUR8apP CFqsNdB6LaXGBX78l2MR0igyeDovZrvzJPm53oKQH2p+CslPQ08E5Gb9OCDnbnYK0n3kg2aX UN7Q3wXkm32hOUgenaKiqSJaL6G1hbqiYq0yFb9wSXFWEZ8QQ0QRSWQiLtFSGjoVz8jOicos VrORuKSMUhtZKodiGDw6LUWvMxpoiUrHGFLxfIKQSYmYRKlMJpPGxRYky+JZyTVaZXdPIKXd x8tXOkZ41aA52AR8UYjFweVqt9AE/FAxNgDg6uaQ0HMhxv4C+G3euCu6/eA54ETDALp/fRd4 LkTYQbjdvMA3ARRFsONw3FnioREsAq79buJzeheArmEXn9NHQmuvE/FgPhYOH684vFjA8iNr s943D2BhcGZ7CXhwEHYFDj7d8g4UiF2FjbYmHheQDIcWG7yaACwTbrvqvV5fNnh2Ys0bDLEe Aex/v4pwP8iATvsLwOEA6Lb3Cz1DQ+wIdE6kcvpaAGvftCPcoQXAqS8LPM4QC1cspp3k/XDj T50PZxbBu3fEnEQOV9rnd7LOwOpey06l0zxon54XNoJQ857CzP8LM+8prAMgXeAQXcpolDRD lBJShtIwRq1SWqjT9AHvkkXGD4CWqWwbwFCA+4skFY48sQ9VxlRobACiCB4oerjEUqIiquIG rdcp9E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abafb 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> <5AD0160E.7050601@samsung.com> <5AD017E8.7020901@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:37, arvindY wrote: > > > On Friday 13 April 2018 07:59 AM, Chanwoo Choi wrote: >> 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; >> } > > Yes, You are right. I will share a update patch. > Thanks for reviewing. It is my mistake. 'devfreq' is local variable in the devfreq_dev_release(0. Even if initializes 'devfreq = NULL' in the devfreq_dev_release(), it cannot initialize the 'devfreq' local variable in the devfreq_add_device(). I think that your original patch is good. Reviewed-by: Chanwoo Choi >> >>>>>> err_dev: >>>>>> if (devfreq) >>>>>> kfree(devfreq); >>>>>> >>> ~arvind >>> >>> >>> >> > > > > -- Best Regards, Chanwoo Choi Samsung Electronics