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

Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj

stable inclusion
from stable-v5.10.102
commit 91d8866ca55232d21995a3d54fac96de33c9e20c
bugzilla: https://gitee.com/openeuler/kernel/issues/I567K6

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

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

[ Upstream commit 8bc69f86 ]

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: c2e5df61 ("vmbus: add per-channel sysfs info")
Signed-off-by: NMiaoqian Lin <linmq006@gmail.com>
Reviewed-by: NJuan Vazquez <juvazq@linux.microsoft.com>
Link: https://lore.kernel.org/r/20220203173008.43480-1-linmq006@gmail.comSigned-off-by: NWei Liu <wei.liu@kernel.org>
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>
上级 198d3f9a
...@@ -1944,8 +1944,10 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) ...@@ -1944,8 +1944,10 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
kobj->kset = dev->channels_kset; kobj->kset = dev->channels_kset;
ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL, ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL,
"%u", relid); "%u", relid);
if (ret) if (ret) {
kobject_put(kobj);
return ret; return ret;
}
ret = sysfs_create_group(kobj, &vmbus_chan_group); ret = sysfs_create_group(kobj, &vmbus_chan_group);
...@@ -1954,6 +1956,7 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) ...@@ -1954,6 +1956,7 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
* The calling functions' error handling paths will cleanup the * The calling functions' error handling paths will cleanup the
* empty channel directory. * empty channel directory.
*/ */
kobject_put(kobj);
dev_err(device, "Unable to set up channel sysfs files\n"); dev_err(device, "Unable to set up channel sysfs files\n");
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册