Skip to content

Commit

Permalink
Driver core: Don't leak 'old_class_name' in drivers/base/core.c::devi…
Browse files Browse the repository at this point in the history
…ce_rename()

If kmalloc() fails to allocate space for 'old_symlink_name' in
drivers/base/core.c::device_rename(), then we'll leak 'old_class_name'.

Spotted by the Coverity checker.


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Jesper Juhl authored and Greg Kroah-Hartman committed Oct 18, 2006
1 parent 221c324 commit 952ab43
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,10 @@ int device_rename(struct device *dev, char *new_name)

if (dev->class) {
old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
if (!old_symlink_name)
return -ENOMEM;
if (!old_symlink_name) {
error = -ENOMEM;
goto out_free_old_class;
}
strlcpy(old_symlink_name, dev->bus_id, BUS_ID_SIZE);
}

Expand All @@ -834,9 +836,10 @@ int device_rename(struct device *dev, char *new_name)
}
put_device(dev);

kfree(old_class_name);
kfree(new_class_name);
kfree(old_symlink_name);
out_free_old_class:
kfree(old_class_name);

return error;
}

0 comments on commit 952ab43

Please sign in to comment.