From: Zhang Rui <rui.zhang@intel.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Durgadoss R <durgadoss.r@intel.com>,
eduardo.valentin@ti.com, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org, hongbo.zhang@freescale.com,
wni@nvidia.com
Subject: Re: [PATCHv5 01/10] Thermal: Do kfree in _unregister functions
Date: Mon, 03 Mar 2014 21:44:16 +0800 [thread overview]
Message-ID: <1393854256.2193.2.camel@rzhang1-mobl4> (raw)
In-Reply-To: <20140121194624.GA29615@core.coreip.homeip.net>
On Tue, 2014-01-21 at 11:46 -0800, Dmitry Torokhov wrote:
> Hi Durgadoss,
>
> On Fri, Jan 17, 2014 at 05:26:18AM +0530, Durgadoss R wrote:
> > Currently the thermal_release function does
> > kfree for all devices when they call device_unregister.
> > This makes code scattering i.e whenever we add new
> > devices (to thermal class) we need to add its
> > corresponding kfree in thermal_release function.
> > And the if-else is also growing lengthy.
> >
> > Instead, do all kfree() of devices in their own
> > _unregister functions. This makes the code look
> > clean and easy to maintain.
> >
> > Signed-off-by: Durgadoss R <durgadoss.r@intel.com>
> > ---
> > drivers/thermal/thermal_core.c | 17 +++++------------
> > 1 file changed, 5 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> > index 338a88b..165afc6 100644
> > --- a/drivers/thermal/thermal_core.c
> > +++ b/drivers/thermal/thermal_core.c
> > @@ -1042,18 +1042,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device);
> >
> > static void thermal_release(struct device *dev)
> > {
> > - struct thermal_zone_device *tz;
> > - struct thermal_cooling_device *cdev;
> > -
> > - if (!strncmp(dev_name(dev), "thermal_zone",
> > - sizeof("thermal_zone") - 1)) {
> > - tz = to_thermal_zone(dev);
> > - kfree(tz);
> > - } else if(!strncmp(dev_name(dev), "cooling_device",
> > - sizeof("cooling_device") - 1)){
> > - cdev = to_cooling_device(dev);
> > - kfree(cdev);
> > - }
> > + /* No-op since kfree(dev) is done in _unregister functions */
> > }
> >
> > static struct class thermal_class = {
> > @@ -1146,6 +1135,7 @@ __thermal_cooling_device_register(struct device_node *np,
> > unregister:
> > release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
> > device_unregister(&cdev->device);
> > + kfree(cdev);
>
> This is broken, you can not assume that you are holding the last
> reference. Please observe help text of DEBUG_KOBJECT_RELEASE config
> option, activate said option and try unregistering thermal device.
>
agreed.
If you think it is too complicated to support the different thermal
components in thermal_release(), we can introduce per device .release()
callback as well.
thanks,
rui
> Thanks.
>
next prev parent reply other threads:[~2014-03-03 13:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-16 23:56 [PATCHv5 00/10] Thermal Framework Enhancements Durgadoss R
2014-01-16 23:56 ` [PATCHv5 01/10] Thermal: Do kfree in _unregister functions Durgadoss R
2014-01-21 19:46 ` Dmitry Torokhov
2014-03-03 13:44 ` Zhang Rui [this message]
2014-01-16 23:56 ` [PATCHv5 02/10] Thermal: Create sensor level APIs Durgadoss R
2014-01-16 23:56 ` [PATCHv5 03/10] Thermal: Add cooling device APIs Durgadoss R
2014-01-17 7:57 ` R, Durgadoss
2014-01-16 23:56 ` [PATCHv5 04/10] Thermal: Create zone level APIs Durgadoss R
2014-01-16 23:56 ` [PATCHv5 05/10] Thermal: Add APIs to bind cdev to new zone structure Durgadoss R
2014-01-16 23:56 ` [PATCHv5 06/10] Thermal: Add trip point sysfs nodes for sensor Durgadoss R
2014-01-16 23:56 ` [PATCHv5 07/10] Thermal: Create Thermal map sysfs attributes for a zone Durgadoss R
2014-01-16 23:56 ` [PATCHv5 08/10] Thermal: Add Documentation to new APIs Durgadoss R
2014-01-16 23:56 ` [PATCHv5 09/10] Thermal: Add ABI Documentation for sysfs interfaces Durgadoss R
2014-01-16 23:56 ` [PATCHv5 10/10] Thermal: Dummy driver used for testing Durgadoss R
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1393854256.2193.2.camel@rzhang1-mobl4 \
--to=rui.zhang@intel.com \
--cc=dmitry.torokhov@gmail.com \
--cc=durgadoss.r@intel.com \
--cc=eduardo.valentin@ti.com \
--cc=hongbo.zhang@freescale.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=wni@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).