Skip to content

Commit 91d8866

Browse files
Yuuoniygregkh
authored andcommitted
Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj
[ Upstream commit 8bc69f8 ] 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: c2e5df6 ("vmbus: add per-channel sysfs info") Signed-off-by: Miaoqian Lin <linmq006@gmail.com> Reviewed-by: Juan Vazquez <juvazq@linux.microsoft.com> Link: https://lore.kernel.org/r/20220203173008.43480-1-linmq006@gmail.com Signed-off-by: Wei Liu <wei.liu@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a176d55 commit 91d8866

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎drivers/hv/vmbus_drv.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,8 +1944,10 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
19441944
kobj->kset = dev->channels_kset;
19451945
ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL,
19461946
"%u", relid);
1947-
if (ret)
1947+
if (ret) {
1948+
kobject_put(kobj);
19481949
return ret;
1950+
}
19491951

19501952
ret = sysfs_create_group(kobj, &vmbus_chan_group);
19511953

@@ -1954,6 +1956,7 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
19541956
* The calling functions' error handling paths will cleanup the
19551957
* empty channel directory.
19561958
*/
1959+
kobject_put(kobj);
19571960
dev_err(device, "Unable to set up channel sysfs files\n");
19581961
return ret;
19591962
}

0 commit comments

Comments
 (0)