The IDR API is deprecated. Use an XArray to track tty minors. The XA_LIMIT range covers the same 0..GB_NUM_MINORS-1 minors as the old idr_alloc() call, and -EBUSY from a full array is mapped back to the -ENOSPC that callers used to get.
No change to the tty interface or to which minors are assigned.
Signed-off-by: Chhabilal Dangal yogeshdangal66@gmail.com --- drivers/staging/greybus/uart.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c index e1b73db6a..d7a136fcd 100644 --- a/drivers/staging/greybus/uart.c +++ b/drivers/staging/greybus/uart.c @@ -22,7 +22,7 @@ #include <linux/serial.h> #include <linux/tty_driver.h> #include <linux/tty_flip.h> -#include <linux/idr.h> +#include <linux/xarray.h> #include <linux/fs.h> #include <linux/kdev_t.h> #include <linux/kfifo.h> @@ -66,7 +66,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) @@ -341,7 +341,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) { @@ -358,13 +358,19 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
static int alloc_minor(struct gb_tty *gb_tty) { - int minor; + u32 minor; + int ret;
mutex_lock(&table_lock); - minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL); + ret = xa_alloc(&tty_minors, &minor, gb_tty, + XA_LIMIT(0, GB_NUM_MINORS - 1), GFP_KERNEL); mutex_unlock(&table_lock); - if (minor >= 0) - gb_tty->minor = minor; + if (ret == -EBUSY) + ret = -ENOSPC; + if (ret) + return ret; + + gb_tty->minor = minor; return minor; }
@@ -374,7 +380,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); }
@@ -991,7 +997,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[] = {
On Mon, Nov 23, 2026 at 08:30:56PM +0545, Chhabilal Dangal wrote:
The IDR API is deprecated. Use an XArray to track tty minors. The XA_LIMIT range covers the same 0..GB_NUM_MINORS-1 minors as the old idr_alloc() call, and -EBUSY from a full array is mapped back to the -ENOSPC that callers used to get.
No change to the tty interface or to which minors are assigned.
Please read the mailing list archives for why this patch keeps getting rejected.
thanks,
greg k-h