Skip to content

Commit 8bc69f8

Browse files
Yuuoniyliuw
authored andcommitted
Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj
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>
1 parent 3149efc commit 8bc69f8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,8 +2028,10 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
20282028
kobj->kset = dev->channels_kset;
20292029
ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL,
20302030
"%u", relid);
2031-
if (ret)
2031+
if (ret) {
2032+
kobject_put(kobj);
20322033
return ret;
2034+
}
20332035

20342036
ret = sysfs_create_group(kobj, &vmbus_chan_group);
20352037

@@ -2038,6 +2040,7 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
20382040
* The calling functions' error handling paths will cleanup the
20392041
* empty channel directory.
20402042
*/
2043+
kobject_put(kobj);
20412044
dev_err(device, "Unable to set up channel sysfs files\n");
20422045
return ret;
20432046
}

0 commit comments

Comments
 (0)