2020-11-05 18:20:21

by Deepak R Varma

[permalink] [raw]
Subject: [PATCH] drm/vc4: replace idr_init() by idr_init_base()

idr_init() uses base 0 which is an invalid identifier for this driver.
The idr_alloc for this driver uses VC4_PERFMONID_MIN as start value for
ID range and it is #defined to 1. The new function idr_init_base allows
IDR to set the ID lookup from base 1. This avoids all lookups that
otherwise starts from 0 since 0 is always unused / available.

References: commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient")

Signed-off-by: Deepak R Varma <[email protected]>
---
drivers/gpu/drm/vc4/vc4_perfmon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
index f4aa75efd16b..7d40f421d922 100644
--- a/drivers/gpu/drm/vc4/vc4_perfmon.c
+++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
@@ -77,7 +77,7 @@ struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id)
void vc4_perfmon_open_file(struct vc4_file *vc4file)
{
mutex_init(&vc4file->perfmon.lock);
- idr_init(&vc4file->perfmon.idr);
+ idr_init_base(&vc4file->perfmon.idr, 1);
}

static int vc4_perfmon_idr_del(int id, void *elem, void *data)
--
2.25.1


2020-11-05 19:28:04

by Eric Anholt

[permalink] [raw]
Subject: Re: [PATCH] drm/vc4: replace idr_init() by idr_init_base()

On Thu, Nov 5, 2020 at 10:25 AM Deepak R Varma <[email protected]> wrote:
>
> idr_init() uses base 0 which is an invalid identifier for this driver.
> The idr_alloc for this driver uses VC4_PERFMONID_MIN as start value for
> ID range and it is #defined to 1. The new function idr_init_base allows
> IDR to set the ID lookup from base 1. This avoids all lookups that
> otherwise starts from 0 since 0 is always unused / available.
>
> References: commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient")
>
> Signed-off-by: Deepak R Varma <[email protected]>
> ---
> drivers/gpu/drm/vc4/vc4_perfmon.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
> index f4aa75efd16b..7d40f421d922 100644
> --- a/drivers/gpu/drm/vc4/vc4_perfmon.c
> +++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
> @@ -77,7 +77,7 @@ struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id)
> void vc4_perfmon_open_file(struct vc4_file *vc4file)
> {
> mutex_init(&vc4file->perfmon.lock);
> - idr_init(&vc4file->perfmon.idr);
> + idr_init_base(&vc4file->perfmon.idr, 1);
> }

Sounds like you should use VC4_PERFMONID_MIN instead of a magic 1 here.

2020-11-05 19:37:11

by Deepak R Varma

[permalink] [raw]
Subject: Re: [PATCH] drm/vc4: replace idr_init() by idr_init_base()

On Thu, Nov 05, 2020 at 11:25:11AM -0800, Eric Anholt wrote:
> On Thu, Nov 5, 2020 at 10:25 AM Deepak R Varma <[email protected]> wrote:
> >
> > idr_init() uses base 0 which is an invalid identifier for this driver.
> > The idr_alloc for this driver uses VC4_PERFMONID_MIN as start value for
> > ID range and it is #defined to 1. The new function idr_init_base allows
> > IDR to set the ID lookup from base 1. This avoids all lookups that
> > otherwise starts from 0 since 0 is always unused / available.
> >
> > References: commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient")
> >
> > Signed-off-by: Deepak R Varma <[email protected]>
> > ---
> > drivers/gpu/drm/vc4/vc4_perfmon.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
> > index f4aa75efd16b..7d40f421d922 100644
> > --- a/drivers/gpu/drm/vc4/vc4_perfmon.c
> > +++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
> > @@ -77,7 +77,7 @@ struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id)
> > void vc4_perfmon_open_file(struct vc4_file *vc4file)
> > {
> > mutex_init(&vc4file->perfmon.lock);
> > - idr_init(&vc4file->perfmon.idr);
> > + idr_init_base(&vc4file->perfmon.idr, 1);
> > }
>
> Sounds like you should use VC4_PERFMONID_MIN instead of a magic 1 here.

Agreed. I will update and resend v2.

Thank you,
./drv