[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20100712124904.d05242d2.akpm@linux-foundation.org>
Date: Mon, 12 Jul 2010 12:49:04 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Axel Lin <axel.lin@...il.com>
Cc: linux-kernel <linux-kernel@...r.kernel.org>,
Stephen Hemminger <shemminger@...tta.com>,
Jens Axboe <jens.axboe@...cle.com>,
David Teigland <teigland@...hat.com>,
Pekka Enberg <penberg@...helsinki.fi>,
"Hans J. Koch" <hjk@...utronix.de>
Subject: Re: [PATCH] edd: fix possible memory leak in edd_init() error path
On Fri, 09 Jul 2010 18:50:07 +0800
Axel Lin <axel.lin@...il.com> 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@...il.com>
> ---
> 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)
This test is unneeded?
> + edd_device_unregister(edev);
> + }
> + kset_unregister(edd_kset);
> return rc;
> }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists