vdpa_sim_blk: switch to dynamic root device

Driver core expects devices to be dynamically allocated and will, for
example, complain loudly when no release function has been provided.

Use root_device_register() to allocate and register the root device
instead of open coding using a static device.

Signed-off-by: Johan Hovold <johan@kernel.org>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20260424104703.2619093-2-johan@kernel.org>
This commit is contained in:
Johan Hovold 2026-04-24 12:47:02 +02:00 committed by Michael S. Tsirkin
parent 7cdaeef19b
commit 4f3da991b5

View File

@ -397,14 +397,7 @@ static void vdpasim_blk_free(struct vdpasim *vdpasim)
kvfree(blk->buffer);
}
static void vdpasim_blk_mgmtdev_release(struct device *dev)
{
}
static struct device vdpasim_blk_mgmtdev = {
.init_name = "vdpasim_blk",
.release = vdpasim_blk_mgmtdev_release,
};
static struct device *vdpasim_blk_mgmtdev;
static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
const struct vdpa_dev_set_config *config)
@ -475,7 +468,6 @@ static struct virtio_device_id id_table[] = {
};
static struct vdpa_mgmt_dev mgmt_dev = {
.device = &vdpasim_blk_mgmtdev,
.id_table = id_table,
.ops = &vdpasim_blk_mgmtdev_ops,
};
@ -484,12 +476,11 @@ static int __init vdpasim_blk_init(void)
{
int ret;
ret = device_register(&vdpasim_blk_mgmtdev);
if (ret) {
put_device(&vdpasim_blk_mgmtdev);
return ret;
}
vdpasim_blk_mgmtdev = root_device_register("vdpasim_blk");
if (IS_ERR(vdpasim_blk_mgmtdev))
return PTR_ERR(vdpasim_blk_mgmtdev);
mgmt_dev.device = vdpasim_blk_mgmtdev;
ret = vdpa_mgmtdev_register(&mgmt_dev);
if (ret)
goto parent_err;
@ -507,7 +498,8 @@ static int __init vdpasim_blk_init(void)
mgmt_dev_err:
vdpa_mgmtdev_unregister(&mgmt_dev);
parent_err:
device_unregister(&vdpasim_blk_mgmtdev);
root_device_unregister(vdpasim_blk_mgmtdev);
return ret;
}
@ -515,7 +507,7 @@ static void __exit vdpasim_blk_exit(void)
{
kvfree(shared_buffer);
vdpa_mgmtdev_unregister(&mgmt_dev);
device_unregister(&vdpasim_blk_mgmtdev);
root_device_unregister(vdpasim_blk_mgmtdev);
}
module_init(vdpasim_blk_init)