power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init
authorMiaoqian Lin <linmq006@gmail.com>
Mon, 24 Jan 2022 13:13:46 +0000 (13:13 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Apr 2022 07:08:16 +0000 (09:08 +0200)
commit19aa3c98ed7b2616e105946cec804f897837ab84
tree45acf9c13d70bc1fa0e51869981dca5dd115b75d
parenta2ccf3fddb5c5ae2b50e6d607415f10c30ce9fe0
power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init

[ Upstream commit 6a4760463dbc6b603690938c468839985189ce0a ]

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 memory leak by calling kobject_put().

Fixes: 8c0984e5a753 ("power: move power supply drivers to power/supply")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/power/supply/ab8500_fg.c