Skip to content

Commit

Permalink
edd: fix possible memory leak in edd_init() error path
Browse files Browse the repository at this point in the history
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 <axel.lin@gmail.com>
Cc: Stephen Hemminger <shemminger@vyatta.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
AxelLin authored and torvalds committed Aug 10, 2010
1 parent ea98eed commit 1986aaf
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions drivers/firmware/edd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down

0 comments on commit 1986aaf

Please sign in to comment.