Skip to content

Commit

Permalink
power_supply: Fix use after free and memory leak
Browse files Browse the repository at this point in the history
device_unregister() might free its argument.  This leads to freed
memory use in kfree().  Also use put_device() instead of kfree()
as dev may be already used in another layer after call to device_add().

Signed-off-by: Vasiliy Kulikov <segoon@openwall.com>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
  • Loading branch information
Vasiliy Kulikov authored and Anton Vorontsov committed Dec 21, 2010
1 parent 26eb387 commit 3a2dbd6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/power/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
goto success;

create_triggers_failed:
device_unregister(psy->dev);
device_del(dev);
kobject_set_name_failed:
device_add_failed:
kfree(dev);
put_device(dev);
success:
return rc;
}
Expand Down

0 comments on commit 3a2dbd6

Please sign in to comment.