Linux kernel staging patches
 help / color / mirror / Atom feed
* [PATCH] staging: greybus: uart: replace IDR with XArray
@ 2026-06-16 19:07 Jack Lee
  2026-06-17  1:26 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jack Lee @ 2026-06-16 19:07 UTC (permalink / raw)
  To: dtwlin, johan, elder, gregkh
  Cc: greybus-dev, linux-staging, linux-kernel, Jack Lee

DEFINE_IDR is deprecated in favor of XArray. Convert tty_minors
from IDR to XArray, replacing idr_alloc, idr_find, idr_remove and
idr_destroy with their xa_alloc, xa_load, xa_erase and xa_destroy
equivalents.

Signed-off-by: Jack Lee <skunkolee@gmail.com>
---
 drivers/staging/greybus/uart.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 7d060b4cd33d..30afcd0caa14 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -22,13 +22,13 @@
 #include <linux/serial.h>
 #include <linux/tty_driver.h>
 #include <linux/tty_flip.h>
-#include <linux/idr.h>
 #include <linux/fs.h>
 #include <linux/kdev_t.h>
 #include <linux/kfifo.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
 #include <linux/greybus.h>
+#include <linux/xarray.h>
 
 #include "gbphy.h"
 
@@ -67,7 +67,7 @@ struct gb_tty {
 };
 
 static struct tty_driver *gb_tty_driver;
-static DEFINE_IDR(tty_minors);
+static DEFINE_XARRAY_ALLOC(tty_minors);
 static DEFINE_MUTEX(table_lock);
 
 static int gb_uart_receive_data_handler(struct gb_operation *op)
@@ -342,7 +342,7 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
 	struct gb_tty *gb_tty;
 
 	mutex_lock(&table_lock);
-	gb_tty = idr_find(&tty_minors, minor);
+	gb_tty = xa_load(&tty_minors, minor);
 	if (gb_tty) {
 		mutex_lock(&gb_tty->mutex);
 		if (gb_tty->disconnected) {
@@ -359,14 +359,13 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
 
 static int alloc_minor(struct gb_tty *gb_tty)
 {
-	int minor;
+	int ret;
 
-	mutex_lock(&table_lock);
-	minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
-	mutex_unlock(&table_lock);
-	if (minor >= 0)
-		gb_tty->minor = minor;
-	return minor;
+	ret = xa_alloc(&tty_minors, &gb_tty->minor, gb_tty,
+		       XA_LIMIT(0, GB_NUM_MINORS - 1), GFP_KERNEL);
+	if (ret)
+		return ret;
+	return gb_tty->minor;
 }
 
 static void release_minor(struct gb_tty *gb_tty)
@@ -375,7 +374,7 @@ static void release_minor(struct gb_tty *gb_tty)
 
 	gb_tty->minor = 0;	/* Maybe should use an invalid value instead */
 	mutex_lock(&table_lock);
-	idr_remove(&tty_minors, minor);
+	xa_erase(&tty_minors, minor);
 	mutex_unlock(&table_lock);
 }
 
@@ -984,7 +983,7 @@ static void gb_tty_exit(void)
 {
 	tty_unregister_driver(gb_tty_driver);
 	tty_driver_kref_put(gb_tty_driver);
-	idr_destroy(&tty_minors);
+	xa_destroy(&tty_minors);
 }
 
 static const struct gbphy_device_id gb_uart_id_table[] = {
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: greybus: uart: replace IDR with XArray
  2026-06-16 19:07 [PATCH] staging: greybus: uart: replace IDR with XArray Jack Lee
@ 2026-06-17  1:26 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-06-17  1:26 UTC (permalink / raw)
  To: Jack Lee; +Cc: dtwlin, johan, elder, greybus-dev, linux-staging, linux-kernel

On Tue, Jun 16, 2026 at 12:07:03PM -0700, Jack Lee wrote:
> DEFINE_IDR is deprecated in favor of XArray. Convert tty_minors
> from IDR to XArray, replacing idr_alloc, idr_find, idr_remove and
> idr_destroy with their xa_alloc, xa_load, xa_erase and xa_destroy
> equivalents.
> 
> Signed-off-by: Jack Lee <skunkolee@gmail.com>
> ---
>  drivers/staging/greybus/uart.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 

This "cleanup" has come up in the past, and shot down each time as it's
not really needed or necessary.  idr is just fine to use here and xarray
is overkill.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-17  1:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-16 19:07 [PATCH] staging: greybus: uart: replace IDR with XArray Jack Lee
2026-06-17  1:26 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox