From: Pekka Enberg <penberg@cs.helsinki.fi>
To: Axel Lin <axel.lin@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
Stephen Hemminger <shemminger@vyatta.com>,
Jens Axboe <jens.axboe@oracle.com>,
David Teigland <teigland@redhat.com>,
"Hans J. Koch" <hjk@linutronix.de>
Subject: Re: [PATCH] edd: fix possible memory leak in edd_init() error path
Date: Sun, 11 Jul 2010 12:01:26 +0300 [thread overview]
Message-ID: <4C398866.8050304@cs.helsinki.fi> (raw)
In-Reply-To: <1278672607.1335.3.camel@mola>
Axel Lin wrote:
> The error may happen at any iteration of the for loop,
> this patch properly unregisters already registed edd_devices in error path.
>
> Signed-off-by: Axel Lin <axel.lin@gmail.com>
Looks good to me.
Reviewed-by: Pekka Enberg <penberg@cs.helsinki.fi>
> ---
> drivers/firmware/edd.c | 23 ++++++++++++++++-------
> 1 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
> index 110e24e..b75082c 100644
> --- a/drivers/firmware/edd.c
> +++ b/drivers/firmware/edd.c
> @@ -744,7 +744,7 @@ static inline int edd_num_devices(void)
> static int __init
> edd_init(void)
> {
> - unsigned int i;
> + int i;
> int rc=0;
> struct edd_device *edev;
>
> @@ -760,21 +760,30 @@ edd_init(void)
> if (!edd_kset)
> return -ENOMEM;
>
> - for (i = 0; i < edd_num_devices() && !rc; i++) {
> + for (i = 0; i < edd_num_devices(); i++) {
> edev = kzalloc(sizeof (*edev), GFP_KERNEL);
> - if (!edev)
> - return -ENOMEM;
> + if (!edev) {
> + rc = -ENOMEM;
> + goto out;
> + }
>
> rc = edd_device_register(edev, i);
> if (rc) {
> kfree(edev);
> - break;
> + goto out;
> }
> edd_devices[i] = edev;
> }
>
> - if (rc)
> - kset_unregister(edd_kset);
> + return 0;
> +
> +out:
> + while (--i >= 0) {
> + edev = edd_devices[i];
> + if (edev)
> + edd_device_unregister(edev);
> + }
> + kset_unregister(edd_kset);
> return rc;
> }
>
next prev parent reply other threads:[~2010-07-11 9:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-09 10:50 [PATCH] edd: fix possible memory leak in edd_init() error path Axel Lin
2010-07-11 9:01 ` Pekka Enberg [this message]
2010-07-12 19:49 ` Andrew Morton
2010-07-13 1:17 ` Axel Lin
2010-07-13 1:29 ` Andrew Morton
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=4C398866.8050304@cs.helsinki.fi \
--to=penberg@cs.helsinki.fi \
--cc=axel.lin@gmail.com \
--cc=hjk@linutronix.de \
--cc=jens.axboe@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=shemminger@vyatta.com \
--cc=teigland@redhat.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