提交 d4f4952c 编写于 作者: M Miaoqian Lin 提交者: Zheng Zengkai

power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init

stable inclusion
from stable-v5.10.110
commit 879356a6a05559582b0a7895d86d2d4359745c08
bugzilla: https://gitee.com/openeuler/kernel/issues/I574AL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=879356a6a05559582b0a7895d86d2d4359745c08

--------------------------------

[ Upstream commit 6a476046 ]

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: 8c0984e5 ("power: move power supply drivers to power/supply")
Signed-off-by: NMiaoqian Lin <linmq006@gmail.com>
Signed-off-by: NSebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYu Liao <liaoyu15@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 d0ac041e
......@@ -2541,8 +2541,10 @@ static int ab8500_fg_sysfs_init(struct ab8500_fg *di)
ret = kobject_init_and_add(&di->fg_kobject,
&ab8500_fg_ktype,
NULL, "battery");
if (ret < 0)
if (ret < 0) {
kobject_put(&di->fg_kobject);
dev_err(di->dev, "failed to create sysfs entry\n");
}
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册