Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Cc: Yangtao Li <tiny.windzz@gmail.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Samuel Holland <samuel@sholland.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] cpufreq: sun50i: fix memory leak in dt_has_supported_hw()
Date: Fri, 10 May 2024 17:49:37 +0100	[thread overview]
Message-ID: <20240510174937.0a710104@donnerap.manchester.arm.com> (raw)
In-Reply-To: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-1-0a2352cac46b@gmail.com>

On Fri, 03 May 2024 19:52:32 +0200
Javier Carrasco <javier.carrasco.cruz@gmail.com> wrote:

Hi Javier,

> The for_each_child_of_node() loop does not decrement the child node
> refcount before the break instruction, even though the node is no
> longer required.

Ah, thanks for spotting this, there is indeed a leak. Sorry for the
blunder!

> This can be avoided with the new for_each_child_of_node_scoped() macro
> that removes the need for any of_node_put().

Wow, that's the typical convoluted Linux macro, but it looks correct to me.
It would call the put even if the loop ends naturally, but there is a NULL
test in there, so that's fine.

> Fixes: fa5aec9561cf ("cpufreq: sun50i: Add support for opp_supported_hw")
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Thanks!
Andre

> ---
>  drivers/cpufreq/sun50i-cpufreq-nvmem.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> index 0b882765cd66..ef83e4bf2639 100644
> --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> @@ -131,7 +131,7 @@ static const struct of_device_id cpu_opp_match_list[] = {
>  static bool dt_has_supported_hw(void)
>  {
>  	bool has_opp_supported_hw = false;
> -	struct device_node *np, *opp;
> +	struct device_node *np;
>  	struct device *cpu_dev;
>  
>  	cpu_dev = get_cpu_device(0);
> @@ -142,7 +142,7 @@ static bool dt_has_supported_hw(void)
>  	if (!np)
>  		return false;
>  
> -	for_each_child_of_node(np, opp) {
> +	for_each_child_of_node_scoped(np, opp) {
>  		if (of_find_property(opp, "opp-supported-hw", NULL)) {
>  			has_opp_supported_hw = true;
>  			break;
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-05-10 16:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 17:52 [PATCH 0/2] cpufreq: sun50i: fix memory leak and remove of_node_put() Javier Carrasco
2024-05-03 17:52 ` [PATCH 1/2] cpufreq: sun50i: fix memory leak in dt_has_supported_hw() Javier Carrasco
2024-05-10 16:49   ` Andre Przywara [this message]
2024-05-20  7:33     ` Viresh Kumar
2024-05-20  8:26       ` Andre Przywara
2024-05-20  8:34         ` Viresh Kumar
2024-05-03 17:52 ` [PATCH 2/2] cpufreq: sun50i: replace of_node_put() with automatic cleanup handler Javier Carrasco
2024-05-10 17:42   ` Andre Przywara
2024-05-20  8:35     ` Viresh Kumar
2024-05-20  9:28       ` Markus Elfring
2024-05-20  9:31         ` Viresh Kumar
2024-05-20  9:32 ` [PATCH 0/2] cpufreq: sun50i: fix memory leak and remove of_node_put() Viresh Kumar

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=20240510174937.0a710104@donnerap.manchester.arm.com \
    --to=andre.przywara@arm.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=rafael@kernel.org \
    --cc=samuel@sholland.org \
    --cc=tiny.windzz@gmail.com \
    --cc=viresh.kumar@linaro.org \
    --cc=wens@csie.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