linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Zhang Rui <rui.zhang@intel.com>,
	Lukasz Luba <lukasz.luba@arm.com>,
	Amit Kucheria <amitk@kernel.org>,
	Thara Gopinath <thara.gopinath@gmail.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Vasily Khoruzhick <anarsoul@gmail.com>,
	Yangtao Li <tiny.windzz@gmail.com>, Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Samuel Holland <samuel@sholland.org>, <linux-pm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
	<linux-tegra@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-sunxi@lists.linux.dev>, Chen-Yu Tsai <wenst@chromium.org>
Subject: Re: [PATCH v4 2/6] thermal: of: Use scoped memory and OF handling to simplify thermal_of_trips_init()
Date: Wed, 16 Oct 2024 14:58:51 +0100	[thread overview]
Message-ID: <20241016145851.00004e90@Huawei.com> (raw)
In-Reply-To: <20241010-b4-cleanup-h-of-node-put-thermal-v4-2-bfbe29ad81f4@linaro.org>

On Thu, 10 Oct 2024 20:06:18 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:

> Obtain the device node reference and allocate memory with
> scoped/cleanup.h to reduce error handling and make the code a bit
> simpler.
> 
> The code is not equivalent in one minor aspect: outgoing parameter
> "*ntrips" will not be zeroed on errors of memory allocation.  This
> difference is not important, because code was already not zeroing it in
> case of earlier errors and the only caller does not rely on ntrips being
> 0 in case of errors.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Trivial unrelated comment inline + maybe return_ptr() is the way to go as
Chen-Yu mentioned.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
> 
> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Chen-Yu Tsai <wenst@chromium.org>
> 
> Changes in v4:
> 1. Significant change: kzalloc() also with scoped-handling so the entire
>    error handling could be removed.
> 2. Due to above, drop review-tags (Chen-Yu, Jonathan).
> 
> Changes in v2:
> 1. Drop left-over of_node_put in regular exit path (Chen-Yu)
> ---
>  drivers/thermal/thermal_of.c | 31 ++++++++-----------------------
>  1 file changed, 8 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index f0ffc0e335ba9406f4fd858d6c561f9d23f4b842..37db435b54b124abf25b1d75d6cc4fb75f1c1e5c 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -95,11 +95,9 @@ static int thermal_of_populate_trip(struct device_node *np,
>  
>  static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *ntrips)
>  {
> -	struct thermal_trip *tt;
> -	struct device_node *trips;
>  	int ret, count;
>  
> -	trips = of_get_child_by_name(np, "trips");
> +	struct device_node *trips __free(device_node) = of_get_child_by_name(np, "trips");
>  	if (!trips) {
>  		pr_err("Failed to find 'trips' node\n");
>  		return ERR_PTR(-EINVAL);
> @@ -108,36 +106,23 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
>  	count = of_get_child_count(trips);
>  	if (!count) {
>  		pr_err("No trip point defined\n");
> -		ret = -EINVAL;
> -		goto out_of_node_put;
> +		return ERR_PTR(-EINVAL);
>  	}
>  
> -	tt = kzalloc(sizeof(*tt) * count, GFP_KERNEL);
> -	if (!tt) {
> -		ret = -ENOMEM;
> -		goto out_of_node_put;
> -	}
> -
> -	*ntrips = count;
> +	struct thermal_trip *tt __free(kfree) = kzalloc(sizeof(*tt) * count, GFP_KERNEL);

Trivial and unrelated, but maybe kcalloc(count, sizeof(tt), GFP_KERNEL);

> +	if (!tt)
> +		return ERR_PTR(-ENOMEM);
>  
>  	count = 0;
>  	for_each_child_of_node_scoped(trips, trip) {
>  		ret = thermal_of_populate_trip(trip, &tt[count++]);
>  		if (ret)
> -			goto out_kfree;
> +			return ERR_PTR(ret);
>  	}
>  
> -	of_node_put(trips);
> +	*ntrips = count;
>  
> -	return tt;
> -
> -out_kfree:
> -	kfree(tt);
> -	*ntrips = 0;
> -out_of_node_put:
> -	of_node_put(trips);
> -
> -	return ERR_PTR(ret);
> +	return no_free_ptr(tt);
>  }
>  
>  static struct device_node *of_thermal_zone_find(struct device_node *sensor, int id)
> 



  parent reply	other threads:[~2024-10-16 14:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 18:06 [PATCH v4 0/6] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
2024-10-10 18:06 ` [PATCH v4 1/6] thermal: of: Simplify thermal_of_should_bind with scoped for each OF child Krzysztof Kozlowski
2024-10-10 18:06 ` [PATCH v4 2/6] thermal: of: Use scoped memory and OF handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
2024-10-14  8:24   ` Chen-Yu Tsai
2024-10-16 13:58   ` Jonathan Cameron [this message]
2024-10-10 18:06 ` [PATCH v4 3/6] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
2024-10-10 18:06 ` [PATCH v4 4/6] thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-10-10 18:06 ` [PATCH v4 5/6] thermal: tegra: " Krzysztof Kozlowski
2024-10-10 18:06 ` [PATCH v4 6/6] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
2024-10-14  8:32 ` [PATCH v4 0/6] thermal: scope/cleanup.h improvements Chen-Yu Tsai
2024-10-14  8:40   ` Krzysztof Kozlowski
2024-10-14  8:57     ` Chen-Yu Tsai
2024-11-22 20:43 ` Rafael J. Wysocki

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=20241016145851.00004e90@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=amitk@kernel.org \
    --cc=anarsoul@gmail.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=linux-tegra@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=samuel@sholland.org \
    --cc=thara.gopinath@gmail.com \
    --cc=thierry.reding@gmail.com \
    --cc=tiny.windzz@gmail.com \
    --cc=wens@csie.org \
    --cc=wenst@chromium.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).