Skip to content

Commit f92a4b5

Browse files
Yang Yingliangliuw
authored andcommitted
Drivers: hv: vmbus: fix double free in the error path of vmbus_add_channel_work()
In the error path of vmbus_device_register(), device_unregister() is called, which calls vmbus_device_release(). The latter frees the struct hv_device that was passed in to vmbus_device_register(). So remove the kfree() in vmbus_add_channel_work() to avoid a double free. Fixes: c2e5df6 ("vmbus: add per-channel sysfs info") Suggested-by: Michael Kelley <[email protected]> Signed-off-by: Yang Yingliang <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]>
1 parent c234ba8 commit f92a4b5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/hv/channel_mgmt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,17 @@ static void vmbus_add_channel_work(struct work_struct *work)
533533
* Add the new device to the bus. This will kick off device-driver
534534
* binding which eventually invokes the device driver's AddDevice()
535535
* method.
536+
*
537+
* If vmbus_device_register() fails, the 'device_obj' is freed in
538+
* vmbus_device_release() as called by device_unregister() in the
539+
* error path of vmbus_device_register(). In the outside error
540+
* path, there's no need to free it.
536541
*/
537542
ret = vmbus_device_register(newchannel->device_obj);
538543

539544
if (ret != 0) {
540545
pr_err("unable to add child device object (relid %d)\n",
541546
newchannel->offermsg.child_relid);
542-
kfree(newchannel->device_obj);
543547
goto err_deq_chan;
544548
}
545549

0 commit comments

Comments
 (0)