drivers: hv: vmbus: Fix possible memory leak when device_register() failed
Subsystems (2)
PATCH 1/1 drivers: hv: vmbus: Fix possible memory leak when device_register() failed
The reference must be released when device_register(&child_device_obj->device) failed. Fix this by adding 'put_device()' in the error handling path.
--- drivers/hv/vmbus_drv.c | 1 + 1 file changed, 1 insertion(+)
drivers/hv/vmbus_drv.c +1 -0
@@ -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; }
Signature · 1 line
2.34.1
Quoted 11 lines · Nir Levy
The reference must be released when
device_register(&child_device_obj->device)failed. Fix this by adding 'put_device()' in the error handling path.--- drivers/hv/vmbus_drv.c | 1 + 1 file changed, 1 insertion(+)drivers/hv/vmbus_drv.c +0
-0
drivers/hv/vmbus_drv.c int vmbus_device_register(struct hv_device *child_device_obj) · line 2085
Quoted 4 lines
drivers/hv/vmbus_drv.c +1
-0@@ -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);
I think this patch is not required, as device_add (device_register->device_add) will put_device for any failure within. Please do share the specific flow which you think might need this fix. Thanks.
drivers/hv/vmbus_drv.c int vmbus_device_register(struct hv_device *child_device_obj) · line 2088
Quoted 3 lines
drivers/hv/vmbus_drv.c +0
-0return ret; }
Regards,
~Praveen.
From: Praveen Kumar <[email protected]> Sent: Tuesday, November 22, 2022 4:01 AM
Quoted 15 lines · Nir Levy
Quoted 1 line
The reference must be released when
device_register(&child_device_obj->device)failed.
drivers/hv/vmbus_drv.c int vmbus_device_register(struct hv_device
Quoted 10 lines
Fix this by adding '
put_device()' in the error handling path.--- drivers/hv/vmbus_drv.c | 1 + 1 file changed, 1 insertion(+)drivers/hv/vmbus_drv.c +0
-0@@ -2082,6 +2082,7 @@ int vmbus_device_register(struct hv_device
*child_device_obj)
Quoted 9 lines
drivers/hv/vmbus_drv.c int vmbus_device_register(struct hv_device *child_device_obj) · line 2085
Quoted 4 lines
drivers/hv/vmbus_drv.c +1
-0ret =device_register (&child_device_obj->device);if (ret) {pr_err ("Unable to register child device\n" ); +put_device (&child_device_obj->device);I think this patch is not required, as
device_add(device_register->device_add) willput_devicefor any failure within.
Please do share the specific flow which you think might need this fix. Thanks.
The put_device() done in the exit paths for device_add() pairs with theget_device() done at the very beginning of device_add(). The put_device()
proposed by this patch *is* needed to properly clean up.
But someone else (Yang Yingliang <[email protected]>) has already
submitted a patch to add the put_device(). It's currently in the hyperv-fixes
tree waiting to merge with Linus' tree. See https://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git/commit/?h=hyperv-fixes&id=25c94b051592c010abe92c85b0485f1faedc83f3.
Michael