Skip to content

Commit fa5e555

Browse files
vhost/vsock: Fix error handling in vhost_vsock_init()
Bugzilla: https://bugzilla.redhat.com/2160028 commit 7a4efe1 Author: Yuan Can <yuancan@huawei.com> Date: Tue Nov 8 10:17:05 2022 +0000 vhost/vsock: Fix error handling in vhost_vsock_init() A problem about modprobe vhost_vsock failed is triggered with the following log given: modprobe: ERROR: could not insert 'vhost_vsock': Device or resource busy The reason is that vhost_vsock_init() returns misc_register() directly without checking its return value, if misc_register() failed, it returns without calling vsock_core_unregister() on vhost_transport, resulting the vhost_vsock can never be installed later. A simple call graph is shown as below: vhost_vsock_init() vsock_core_register() # register vhost_transport misc_register() device_create_with_groups() device_create_groups_vargs() dev = kzalloc(...) # OOM happened # return without unregister vhost_transport Fix by calling vsock_core_unregister() when misc_register() returns error. Fixes: 433fc58 ("VSOCK: Introduce vhost_vsock.ko") Signed-off-by: Yuan Can <yuancan@huawei.com> Message-Id: <20221108101705.45981-1-yuancan@huawei.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
1 parent e5f5248 commit fa5e555

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/vhost/vsock.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,14 @@ static int __init vhost_vsock_init(void)
964964
VSOCK_TRANSPORT_F_H2G);
965965
if (ret < 0)
966966
return ret;
967-
return misc_register(&vhost_vsock_misc);
967+
968+
ret = misc_register(&vhost_vsock_misc);
969+
if (ret) {
970+
vsock_core_unregister(&vhost_transport.transport);
971+
return ret;
972+
}
973+
974+
return 0;
968975
};
969976

970977
static void __exit vhost_vsock_exit(void)

0 commit comments

Comments
 (0)