summaryrefslogtreecommitdiff
path: root/drivers/hv
diff options
context:
space:
mode:
authorYang Yingliang <yangyingliang@huawei.com>2022-11-19 11:11:35 +0300
committerWei Liu <wei.liu@kernel.org>2022-11-21 13:57:42 +0300
commit25c94b051592c010abe92c85b0485f1faedc83f3 (patch)
tree9299b91cbe8a38d126b70199f1b7bd68f17df669 /drivers/hv
parentf92a4b50f0bd7fd52391dc4bb9a309085d278f91 (diff)
downloadlinux-25c94b051592c010abe92c85b0485f1faedc83f3.tar.xz
Drivers: hv: vmbus: fix possible memory leak in vmbus_device_register()
If device_register() returns error in vmbus_device_register(), the name allocated by dev_set_name() must be freed. As comment of device_register() says, it should use put_device() to give up the reference in the error path. So fix this by calling put_device(), then the name can be freed in kobject_cleanup(). Fixes: 09d50ff8a233 ("Staging: hv: make the Hyper-V virtual bus code build") Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/20221119081135.1564691-3-yangyingliang@huawei.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
Diffstat (limited to 'drivers/hv')
-rw-r--r--drivers/hv/vmbus_drv.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 8b2e413bf19c..e592c481f7ae 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -2082,6 +2082,7 @@ int vmbus_device_register(struct hv_device *child_device_obj)
ret = device_register(&child_device_obj->device);
if (ret) {
pr_err("Unable to register child device\n");
+ put_device(&child_device_obj->device);
return ret;
}