From: Axel Lin Date: Tue, 10 Aug 2010 00:20:56 +0000 (-0700) Subject: edd: fix possible memory leak in edd_init() error path X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1986aaf828ac8398b3d8d9b4151b08c840414ffe;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git edd: fix possible memory leak in edd_init() error path The error may happen at any iteration of the for loop, this patch properly unregisters already registed edd_devices in error path. [akpm@linux-foundation.org: remove unneeded NULL test] Signed-off-by: Axel Lin Cc: Stephen Hemminger Cc: Jens Axboe Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c index 110e24e50883..f287fe79edc4 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,27 @@ 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) + edd_device_unregister(edd_devices[i]); + kset_unregister(edd_kset); return rc; }