vdpa_sim: switch to use __vdpa_alloc_device()
authorJason Wang <jasowang@redhat.com>
Fri, 23 Dec 2022 05:55:45 +0000 (13:55 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 21 Feb 2023 00:26:57 +0000 (19:26 -0500)
This allows us to control the allocation size of the structure.

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Eugenio PĂ©rez <eperezma@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20221223055548.27810-2-jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vdpa/vdpa_sim/vdpa_sim.c

index 88eab8ded751038ad41327cbc8a48e6cc9acf191..f41f9fc522ee39fd920c81cb8312bea4c3c1b408 100644 (file)
@@ -251,6 +251,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
                               const struct vdpa_dev_set_config *config)
 {
        const struct vdpa_config_ops *ops;
+       struct vdpa_device *vdpa;
        struct vdpasim *vdpasim;
        struct device *dev;
        int i, ret = -ENOMEM;
@@ -268,14 +269,16 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
        else
                ops = &vdpasim_config_ops;
 
-       vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops,
-                                   dev_attr->ngroups, dev_attr->nas,
-                                   dev_attr->name, false);
-       if (IS_ERR(vdpasim)) {
-               ret = PTR_ERR(vdpasim);
+       vdpa = __vdpa_alloc_device(NULL, ops,
+                                  dev_attr->ngroups, dev_attr->nas,
+                                  sizeof(struct vdpasim),
+                                  dev_attr->name, false);
+       if (IS_ERR(vdpa)) {
+               ret = PTR_ERR(vdpa);
                goto err_alloc;
        }
 
+       vdpasim = vdpa_to_sim(vdpa);
        vdpasim->dev_attr = *dev_attr;
        INIT_WORK(&vdpasim->work, dev_attr->work_fn);
        spin_lock_init(&vdpasim->lock);