Linux Power Management development
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@linaro.org>
To: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] ARM: cpuidle: Avoid memleak if init fail
Date: Fri, 1 Sep 2017 09:33:17 +0800	[thread overview]
Message-ID: <20170901013317.GA516@leoy-ThinkPad-T440> (raw)
In-Reply-To: <1504211076-2331-1-git-send-email-stefan.wahren@i2se.com>

Hi Stefan,

On Thu, Aug 31, 2017 at 10:24:36PM +0200, Stefan Wahren wrote:
> In case there are no DT idle states defined or
> cpuidle_register_driver() fails, the copy of the idle driver is leaked:
> 
>     unreferenced object 0xede0dc00 (size 1024):
>     comm "swapper/0", pid 1, jiffies 4294937431 (age 744.510s)
>     hex dump (first 32 bytes):
>     94 9e 0b c1 00 00 00 00 00 00 00 00 00 00 00 00 ................
>     57 46 49 00 00 00 00 00 00 00 00 00 00 00 00 00 WFI.............
>     backtrace:
>     [<c1295f04>] arm_idle_init+0x44/0x1ac
>     [<c0301e6c>] do_one_initcall+0x3c/0x16c
>     [<c1200d70>] kernel_init_freeable+0x110/0x1d0
>     [<c0cb3624>] kernel_init+0x8/0x114
>     [<c0307a98>] ret_from_fork+0x14/0x3c
> 
> So fix this by freeing the unregistered copy in error case.
> 
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> Fixes: d50a7d8acd78 ("ARM: cpuidle: Support asymmetric idle definition")
> ---
>  drivers/cpuidle/cpuidle-arm.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpuidle/cpuidle-arm.c b/drivers/cpuidle/cpuidle-arm.c
> index 7080c38..52a7505 100644
> --- a/drivers/cpuidle/cpuidle-arm.c
> +++ b/drivers/cpuidle/cpuidle-arm.c
> @@ -104,13 +104,13 @@ static int __init arm_idle_init(void)
>  		ret = dt_init_idle_driver(drv, arm_idle_state_match, 1);
>  		if (ret <= 0) {
>  			ret = ret ? : -ENODEV;
> -			goto out_fail;
> +			goto init_fail;
>  		}
>  
>  		ret = cpuidle_register_driver(drv);
>  		if (ret) {
>  			pr_err("Failed to register cpuidle driver\n");
> -			goto out_fail;
> +			goto init_fail;
>  		}
>  
>  		/*
> @@ -149,6 +149,8 @@ static int __init arm_idle_init(void)
>  	}
>  
>  	return 0;
> +init_fail:
> +	kfree(drv);

The below loop only releases resource for previous CPUs, so should check
two variables 'drv' and 'dev'. If 'dev != NULL', we also need to release
it.

Thanks,
Leo Yan

>  out_fail:
>  	while (--cpu >= 0) {
>  		dev = per_cpu(cpuidle_devices, cpu);
> -- 
> 2.7.4
> 

  reply	other threads:[~2017-09-01  1:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 20:24 [PATCH] ARM: cpuidle: Avoid memleak if init fail Stefan Wahren
2017-09-01  1:33 ` Leo Yan [this message]
2017-09-01  5:49   ` Stefan Wahren
2017-09-01  6:56     ` Leo Yan
2017-09-01  7:08       ` Stefan Wahren
2017-09-01  8:10         ` Leo Yan
2017-10-03 13:21 ` Daniel Lezcano

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=20170901013317.GA516@leoy-ThinkPad-T440 \
    --to=leo.yan@linaro.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=stefan.wahren@i2se.com \
    --cc=sudeep.holla@arm.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