power_supply: Fix use after free and memory leak
Vasiliy Kulikov [Fri, 19 Nov 2010 18:41:58 +0000 (21:41 +0300)]
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>

drivers/power/power_supply_core.c

index 91606bb..f06bad0 100644 (file)
@@ -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;
 }