Message ID | 20220128173336.643-1-linmq006@gmail.com |
---|---|
State | New |
Headers | show |
Series | power: supply: ab8500: Fix memory leak in ab8500_chargalg_sysfs_init | expand |
diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c index c4a2fe07126c..658139797509 100644 --- a/drivers/power/supply/ab8500_chargalg.c +++ b/drivers/power/supply/ab8500_chargalg.c @@ -1907,8 +1907,10 @@ static int ab8500_chargalg_sysfs_init(struct ab8500_chargalg *di) ret = kobject_init_and_add(&di->chargalg_kobject, &ab8500_chargalg_ktype, NULL, "ab8500_chargalg"); - if (ret < 0) + if (ret < 0) { dev_err(di->dev, "failed to create sysfs entry\n"); + kobject_put(&di->chargalg_kobject); + } return ret; }
kobject_init_and_add() takes reference even when it fails. According to the doc of kobject_init_and_add() If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. Fix this issue by adding kobject_put(). Fixes: c5b64a990e7f ("power: supply: ab8500: Rename charging algorithm symbols") Signed-off-by: Miaoqian Lin <linmq006@gmail.com> --- drivers/power/supply/ab8500_chargalg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)