Re: [PATCH] staging: greybus: uart: replace IDR with XArray
From: Aviv Levinson
Date: Thu Nov 12 2026 - 11:40:56 EST
Hi Greg,
Thank you for the review.
I am looking to start contributing to the kernel and thought
drivers/staging/ was a good place to start.
I used the checkpatch.pl tool that flagged the use of the deprecated IDR.
I wrote the patch manually and it was only compile tested.
I understand that the use of kref_get_unless_zero() is not a good
practice, so checked current drivers that implement the use of XArray
(drivers/gpu/drm/drm_drv.c) and tried using similar methods that I am
sending in the v2 patch.
בתאריך יום ה׳, 12 בנוב׳ 2026 ב-14:37 מאת Greg KH
<gregkh@xxxxxxxxxxxxxxxxxxx>:
>
> On Wed, Nov 11, 2026 at 08:23:30PM +0200, Aviv Levinson wrote:
> > Migrate the minor number allocation from the legacy IDR API to the
> > modern XArray API to take advantage of its built-in thread safety.
>
> But why?
>
> > As part of this migration, the global `table_lock` mutex has been
> > removed. Mutating operations now rely on XArray's internal spinlocks,
> > and the lookup logic in get_gb_by_minor() has been updated to use
> > rcu_read_lock() combined with kref_get_unless_zero() to safely
> > pin the device reference without blocking.
>
> How was this found and generated and tested?
>
> And kref_get_unless_zero() is almost always a call you never want to
> make.
>
> > Signed-off-by: Aviv Levinson <levinson.aviv@xxxxxxxxx>
> > ---
> > drivers/staging/greybus/uart.c | 37 ++++++++++++++++++----------------
> > 1 file changed, 20 insertions(+), 17 deletions(-)
>
> So now there is more code? That feels like a step backwards, don't you
> think?
>
> thanks,
>
> greg k-h