From: Leo Yan <leo.yan@linaro.org>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Subject: Re: [PATCH 1/2] ARM: cpuidle: refine failure handling in init flow
Date: Sat, 7 Oct 2017 20:12:09 +0800 [thread overview]
Message-ID: <20171007121209.GA23080@leoy-linaro> (raw)
In-Reply-To: <1504507934-14218-1-git-send-email-leo.yan@linaro.org>
On Mon, Sep 04, 2017 at 02:52:13PM +0800, Leo Yan wrote:
> After applied Stefan Wahren patch ("ARM: cpuidle: Avoid memleak if init
> fail") there have no memleak issue, but the code is not consistent to
> handle initialization failure between driver registration and device
> registration. And when device registration fails, it misses to
> unregister the driver.
>
> So this patch is to refine failure handling in init flow, it adds two
> 'goto' tags: when register device fails, it goto 'init_dev_fail' tag and
> free 'dev' structure and unregister driver; when register driver fails,
> it goto 'init_drv_fail' tag and free 'drv' structure.
>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Stefan Wahren <stefan.wahren@i2se.com>
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
Gentle ping...
> ---
> drivers/cpuidle/cpuidle-arm.c | 25 ++++++++++++++++---------
> 1 file changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/cpuidle/cpuidle-arm.c b/drivers/cpuidle/cpuidle-arm.c
> index 52a7505..f419f6a 100644
> --- a/drivers/cpuidle/cpuidle-arm.c
> +++ b/drivers/cpuidle/cpuidle-arm.c
> @@ -86,10 +86,13 @@ static int __init arm_idle_init(void)
>
> for_each_possible_cpu(cpu) {
>
> + drv = NULL;
> + dev = NULL;
> +
> drv = kmemdup(&arm_idle_driver, sizeof(*drv), GFP_KERNEL);
> if (!drv) {
> ret = -ENOMEM;
> - goto out_fail;
> + goto init_drv_fail;
> }
>
> drv->cpumask = (struct cpumask *)cpumask_of(cpu);
> @@ -104,13 +107,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 init_fail;
> + goto init_drv_fail;
> }
>
> ret = cpuidle_register_driver(drv);
> if (ret) {
> pr_err("Failed to register cpuidle driver\n");
> - goto init_fail;
> + goto init_drv_fail;
> }
>
> /*
> @@ -128,14 +131,14 @@ static int __init arm_idle_init(void)
>
> if (ret) {
> pr_err("CPU %d failed to init idle CPU ops\n", cpu);
> - goto out_fail;
> + goto init_dev_fail;
> }
>
> dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> if (!dev) {
> pr_err("Failed to allocate cpuidle device\n");
> ret = -ENOMEM;
> - goto out_fail;
> + goto init_dev_fail;
> }
> dev->cpu = cpu;
>
> @@ -143,15 +146,19 @@ static int __init arm_idle_init(void)
> if (ret) {
> pr_err("Failed to register cpuidle device for CPU %d\n",
> cpu);
> - kfree(dev);
> - goto out_fail;
> + goto init_dev_fail;
> }
> }
>
> return 0;
> -init_fail:
> +
> +init_dev_fail:
> + kfree(dev);
> + cpuidle_unregister_driver(drv);
> +
> +init_drv_fail:
> kfree(drv);
> -out_fail:
> +
> while (--cpu >= 0) {
> dev = per_cpu(cpuidle_devices, cpu);
> cpuidle_unregister_device(dev);
> --
> 2.7.4
>
next prev parent reply other threads:[~2017-10-07 12:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-04 6:52 [PATCH 1/2] ARM: cpuidle: refine failure handling in init flow Leo Yan
2017-09-04 6:52 ` [PATCH 2/2] ARM: cpuidle: replace cpuidle_get_driver with cpuidle_get_cpu_driver Leo Yan
2017-10-07 12:12 ` Leo Yan
2017-09-04 7:00 ` [PATCH 1/2] ARM: cpuidle: refine failure handling in init flow Leo Yan
2017-10-07 12:12 ` Leo Yan [this message]
2017-10-09 12:04 ` Daniel Lezcano
2017-10-09 14:24 ` Leo Yan
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=20171007121209.GA23080@leoy-linaro \
--to=leo.yan@linaro.org \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--cc=stefan.wahren@i2se.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).