From: Zhang Rui <rui.zhang@intel.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>, edubezval@gmail.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 1/3 v2] thermal: core: Add some new helper functions to free resources
Date: Fri, 11 Aug 2017 11:23:48 +0800 [thread overview]
Message-ID: <1502421828.2598.13.camel@intel.com> (raw)
In-Reply-To: <98e96edd53ea3109ec127f82608c8d5df5437c9c.1502201798.git.christophe.jaillet@wanadoo.fr>
On Tue, 2017-08-08 at 16:39 +0200, Christophe JAILLET wrote:
> In order to easily free resources allocated by
> 'thermal_zone_create_device_groups()' we need 2 new helper functions.
>
> The first one undoes 'thermal_zone_create_device_groups()'.
> The 2nd one undoes 'create_trip_attrs()', which is a function called
> by
> 'thermal_zone_create_device_groups()'.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> These functions will be used in patch 2/3 in order to simplify
> 'thermal_release()'
> I've tried to implement it as close a possible as the way the
> resources have
> been allocated.
> However, in 'thermal_release()', the code is simplier without some
> additionnal 'if'.
> No sure if we should prefer consistancy with allocation or simplicity
> of code.
> ---
> drivers/thermal/thermal_core.h | 1 +
> drivers/thermal/thermal_sysfs.c | 29 +++++++++++++++++++++++++++++
> 2 files changed, 30 insertions(+)
>
> diff --git a/drivers/thermal/thermal_core.h
> b/drivers/thermal/thermal_core.h
> index 2412b3759e16..27e3b1df7360 100644
> --- a/drivers/thermal/thermal_core.h
> +++ b/drivers/thermal/thermal_core.h
> @@ -71,6 +71,7 @@ int thermal_build_list_of_policies(char *buf);
>
> /* sysfs I/F */
> int thermal_zone_create_device_groups(struct thermal_zone_device *,
> int);
> +void thermal_zone_destroy_device_groups(struct thermal_zone_device
> *);
> void thermal_cooling_device_setup_sysfs(struct
> thermal_cooling_device *);
> /* used only at binding time */
> ssize_t
> diff --git a/drivers/thermal/thermal_sysfs.c
> b/drivers/thermal/thermal_sysfs.c
> index a694de907a26..eb95d64b9446 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -605,6 +605,24 @@ static int create_trip_attrs(struct
> thermal_zone_device *tz, int mask)
> return 0;
> }
>
> +/**
> + * destroy_trip_attrs() - create attributes for trip points
s/create/destroy
> + * @tz: the thermal zone device
> + *
> + * helper function to free resources alocated by create_trip_attrs()
s/alocated/allocated
thanks,
rui
> + */
> +static void destroy_trip_attrs(struct thermal_zone_device *tz)
> +{
> + if (!tz)
> + return;
> +
> + kfree(tz->trip_type_attrs);
> + kfree(tz->trip_temp_attrs);
> + if (tz->ops->get_trip_hyst)
> + kfree(tz->trip_hyst_attrs);
> + kfree(tz->trips_attribute_group.attrs);
> +}
> +
> int thermal_zone_create_device_groups(struct thermal_zone_device
> *tz,
> int mask)
> {
> @@ -637,6 +655,17 @@ int thermal_zone_create_device_groups(struct
> thermal_zone_device *tz,
> return 0;
> }
>
> +void thermal_zone_destroy_device_groups(struct thermal_zone_device
> *tz)
> +{
> + if (!tz)
> + return;
> +
> + if (tz->trips)
> + destroy_trip_attrs(tz);
> +
> + kfree(tz->device.groups);
> +}
> +
> /* sys I/F for cooling device */
> static ssize_t
> thermal_cooling_device_type_show(struct device *dev,
next prev parent reply other threads:[~2017-08-11 3:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-08 14:39 [PATCH 0/3 v2] thermal: core: Fix some error handling code in 'thermal_zone_device_register()' Christophe JAILLET
2017-08-08 14:39 ` [PATCH 1/3 v2] thermal: core: Add some new helper functions to free resources Christophe JAILLET
2017-08-11 3:23 ` Zhang Rui [this message]
2017-08-11 3:31 ` Zhang Rui
2017-08-11 7:30 ` walter harms
2017-08-11 8:20 ` Zhang Rui
2017-08-08 14:39 ` [PATCH 2/3 v2] thermal: core: Use the new 'thermal_zone_destroy_device_groups()' helper function Christophe JAILLET
2017-08-08 14:39 ` [PATCH 3/3 v2] thermal: core: Fix resources release in error paths in thermal_zone_device_register() Christophe JAILLET
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=1502421828.2598.13.camel@intel.com \
--to=rui.zhang@intel.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=edubezval@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
/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).