Commit 1986aaf8 authored by Axel Lin's avatar Axel Lin Committed by Linus Torvalds

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.

[ remove unneeded NULL test]
Signed-off-by: default avatarAxel Lin <>
Cc: Stephen Hemminger <>
Cc: Jens Axboe <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent ea98eed9
......@@ -744,7 +744,7 @@ static inline int edd_num_devices(void)
static int __init
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) {
goto out;
edd_devices[i] = edev;
if (rc)
return 0;
while (--i >= 0)
return rc;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment