From: Borislav Petkov <bp@alien8.de>
To: Axel Lin <axel.lin@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
Peter Feuerer <peter@piie.net>, Matthew Garrett <mjg@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Len Brown <len.brown@intel.com>,
Alexey Dobriyan <adobriyan@gmail.com>,
platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH] acerhdf: fix resource reclaim in error path
Date: Wed, 7 Jul 2010 10:19:00 +0200 [thread overview]
Message-ID: <20100707081900.GA5308@liondog.tnic> (raw)
In-Reply-To: <1278469339.12801.27.camel@mola>
From: Axel Lin <axel.lin@gmail.com>
Date: Wed, Jul 07, 2010 at 10:22:19AM +0800
Good, I like it. Go down for comments :)
> This patch fix resource reclaim in below cases:
> 1. acerhdf_register_platform() does not properly handle
> platform_device_alloc() failure and platform_device_add() failure.
> This patch adds error handling for acerhdf_register_platform().
> 2. acerhdf_register_platform() return err with acerhdf_dev == NULL.
> as a result, acerhdf_unregister_platform() does not do resource
> reclaim in acerhdf_init() error path.
> This patch adds error handing for acerhdf_register_platform(),
> thus correct the error handing path in acerhdf_init().
> goto out_err instead of err_unreg if acerhdf_register_platform() fail.
> 3. platform_device_del() should be only used in error handling.
> Current implementation missed a platform_device_put() in acerhdf_exit.
> This patch fixes it by using platform_device_unregister() instead of
> platform_device_del() in acerhdf_unregister_platform().
>
> Signed-off-by: Axel Lin <axel.lin@gmail.com>
> ---
> drivers/platform/x86/acerhdf.c | 20 ++++++++++++++++----
> 1 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
> index 7b2384d..e938a86 100644
> --- a/drivers/platform/x86/acerhdf.c
> +++ b/drivers/platform/x86/acerhdf.c
> @@ -579,9 +579,21 @@ static int acerhdf_register_platform(void)
> return err;
>
> acerhdf_dev = platform_device_alloc("acerhdf", -1);
> - platform_device_add(acerhdf_dev);
> + if (!acerhdf_dev) {
> + err = -ENOMEM;
> + goto err_device_alloc;
> + }
> + err = platform_device_add(acerhdf_dev);
> + if (err)
> + goto err_device_add;
>
> return 0;
> +
> +err_device_add:
> + platform_device_put(acerhdf_dev);
> +err_device_alloc:
> + platform_driver_unregister(&acerhdf_driver);
> + return err;
> }
>
> static void acerhdf_unregister_platform(void)
> @@ -589,7 +601,7 @@ static void acerhdf_unregister_platform(void)
> if (!acerhdf_dev)
> return;
while you're at it, you can remove the above check since
platform_device_del() does that anyway and with your error checking,
acerhdf_dev won't be unitialized in this path.
>
> - platform_device_del(acerhdf_dev);
> + platform_device_unregister(acerhdf_dev);
> platform_driver_unregister(&acerhdf_driver);
> }
>
> @@ -633,7 +645,7 @@ static int __init acerhdf_init(void)
>
> err = acerhdf_register_platform();
> if (err)
> - goto err_unreg;
> + goto out_err;
>
> err = acerhdf_register_thermal();
> if (err)
> @@ -646,7 +658,7 @@ err_unreg:
> acerhdf_unregister_platform();
>
> out_err:
> - return -ENODEV;
> + return err;
> }
>
> static void __exit acerhdf_exit(void)
> --
> 1.5.4.3
>
>
>
--
Regards/Gruss,
Boris.
prev parent reply other threads:[~2010-07-07 8:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-07 2:22 [PATCH] acerhdf: fix resource reclaim in error path Axel Lin
2010-07-07 8:19 ` Borislav Petkov [this message]
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=20100707081900.GA5308@liondog.tnic \
--to=bp@alien8.de \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axel.lin@gmail.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mjg@redhat.com \
--cc=peter@piie.net \
--cc=platform-driver-x86@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