[PATCH 1/4] vdpa_sim: switch to use __vdpa_alloc_device()

Jason Wang posted 4 patches 2 years, 9 months ago
There is a newer version of this series
[PATCH 1/4] vdpa_sim: switch to use __vdpa_alloc_device()
Posted by Jason Wang 2 years, 9 months ago
This allows us to control the allocation size of the structure.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index b071f0d842fb..757afef86ba0 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -250,6 +250,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;
@@ -267,14 +268,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);
-- 
2.25.1
Re: [PATCH 1/4] vdpa_sim: switch to use __vdpa_alloc_device()
Posted by Stefano Garzarella 2 years, 8 months ago
On Wed, Dec 21, 2022 at 02:16:49PM +0800, Jason Wang wrote:
>This allows us to control the allocation size of the structure.
>
>Signed-off-by: Jason Wang <jasowang@redhat.com>
>---
> drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>index b071f0d842fb..757afef86ba0 100644
>--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
>+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>@@ -250,6 +250,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;
>@@ -267,14 +268,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);
>-- 
>2.25.1
>