2022-06-08 08:35:46

by Deming Wang

[permalink] [raw]
Subject: [PATCH] virtio: Directly use ida_alloc_range()/ida_free()

Use ida_alloc_range()/ida_free() instead of deprecated
ida_simple_get()/ida_simple_remove() .

Signed-off-by: Deming Wang <[email protected]>
---
drivers/vhost/vdpa.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 935a1d0ddb97..384049cfca8d 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1293,7 +1293,7 @@ static void vhost_vdpa_release_dev(struct device *device)
struct vhost_vdpa *v =
container_of(device, struct vhost_vdpa, dev);

- ida_simple_remove(&vhost_vdpa_ida, v->minor);
+ ida_free(&vhost_vdpa_ida, v->minor);
kfree(v->vqs);
kfree(v);
}
@@ -1316,8 +1316,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
if (!v)
return -ENOMEM;

- minor = ida_simple_get(&vhost_vdpa_ida, 0,
- VHOST_VDPA_DEV_MAX, GFP_KERNEL);
+ minor = ida_alloc_range(&vhost_vdpa_ida, 0, VHOST_VDPA_DEV_MAX - 1, GFP_KERNEL);
if (minor < 0) {
kfree(v);
return minor;
--
2.27.0


2022-06-08 19:47:55

by Christophe JAILLET

[permalink] [raw]
Subject: Re: [PATCH] virtio: Directly use ida_alloc_range()/ida_free()

Hi,

Le 08/06/2022 à 08:08, Deming Wang a écrit :
> Use ida_alloc_range()/ida_free() instead of deprecated
> ida_simple_get()/ida_simple_remove() .
>
> Signed-off-by: Deming Wang <[email protected]>
> ---
> drivers/vhost/vdpa.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 935a1d0ddb97..384049cfca8d 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1293,7 +1293,7 @@ static void vhost_vdpa_release_dev(struct device *device)
> struct vhost_vdpa *v =
> container_of(device, struct vhost_vdpa, dev);
>
> - ida_simple_remove(&vhost_vdpa_ida, v->minor);
> + ida_free(&vhost_vdpa_ida, v->minor);
> kfree(v->vqs);
> kfree(v);
> }
> @@ -1316,8 +1316,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
> if (!v)
> return -ENOMEM;
>
> - minor = ida_simple_get(&vhost_vdpa_ida, 0,
> - VHOST_VDPA_DEV_MAX, GFP_KERNEL);
> + minor = ida_alloc_range(&vhost_vdpa_ida, 0, VHOST_VDPA_DEV_MAX - 1, GFP_KERNEL);

ida_alloc_max() would be better here. It is less verbose.

An explanation in the commit log of why the -1 is needed would also help
reviewer/maintainer, IMHO.

It IS correct, but it is not that obvious without looking at
ida_simple_get() and ida_alloc_range().

CJ


> if (minor < 0) {
> kfree(v);
> return minor;

2022-06-09 01:04:15

by Deming Wang

[permalink] [raw]
Subject: Re: [PATCH] virtio: Directly use ida_alloc_range()/ida_free()

Hi,
> Hi,
>
> Le 08/06/2022 à 08:08, Deming Wang a écrit :
> > Use ida_alloc_range()/ida_free() instead of deprecated
> > ida_simple_get()/ida_simple_remove() .
> >
> > Signed-off-by: Deming Wang <[email protected]>
> > ---
> > drivers/vhost/vdpa.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index
> > 935a1d0ddb97..384049cfca8d 100644
> > --- a/drivers/vhost/vdpa.c
> > +++ b/drivers/vhost/vdpa.c
> > @@ -1293,7 +1293,7 @@ static void vhost_vdpa_release_dev(struct device
> *device)
> > struct vhost_vdpa *v =
> > container_of(device, struct vhost_vdpa, dev);
> >
> > - ida_simple_remove(&vhost_vdpa_ida, v->minor);
> > + ida_free(&vhost_vdpa_ida, v->minor);
> > kfree(v->vqs);
> > kfree(v);
> > }
> > @@ -1316,8 +1316,7 @@ static int vhost_vdpa_probe(struct vdpa_device
> *vdpa)
> > if (!v)
> > return -ENOMEM;
> >
> > - minor = ida_simple_get(&vhost_vdpa_ida, 0,
> > - VHOST_VDPA_DEV_MAX, GFP_KERNEL);
> > + minor = ida_alloc_range(&vhost_vdpa_ida, 0, VHOST_VDPA_DEV_MAX -
> 1,
> > +GFP_KERNEL);
>
> ida_alloc_max() would be better here. It is less verbose.
>
> An explanation in the commit log of why the -1 is needed would also help
> reviewer/maintainer, IMHO.
>
> It IS correct, but it is not that obvious without looking at
> ida_simple_get() and ida_alloc_range().
>
> CJ
>
>
> > if (minor < 0) {
> > kfree(v);
> > return minor;


can I mention one patch about repair ida_free for this.





Attachments:
smime.p7s (3.69 kB)

2022-06-09 05:06:12

by Christophe JAILLET

[permalink] [raw]
Subject: Re: [PATCH] virtio: Directly use ida_alloc_range()/ida_free()

Le 09/06/2022 à 02:42, tomorrow Wang (王德明) a écrit :
>>
>> An explanation in the commit log of why the -1 is needed would also help
>> reviewer/maintainer, IMHO.
>>
>> It IS correct, but it is not that obvious without looking at
>> ida_simple_get() and ida_alloc_range().
>>
>
> can I mention one patch about repair ida_free for this.
>
>

If you manage to find another patch and provide a lore.kernel.org link
to it, I think it should be okay.

However, after a *quick* look in some mailing list, I've not found yet a
description for that.

CJ