* [PATCH] staging: greybus: uart: migrated from IDR to XArray API
@ 2026-02-04 4:38 Neel Bullywon
2026-02-07 13:25 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Neel Bullywon @ 2026-02-04 4:38 UTC (permalink / raw)
To: David Lin
Cc: Johan Hovold, Alex Elder, Greg Kroah-Hartman, greybus-dev,
linux-staging, linux-kernel, Neel Bullywon
Replaced the IDR API with the XArray API for managing TTY minor numbers.
This addresses the checkpatch warning about DEFINE_IDR being deprecated.
Following changes include:
- Replaced DEFINE_IDR with DEFINE_XARRAY_ALLOC
- Replace idr_find with xa_load
- Replace idr_alloc with xa_alloc
- Replace idr_remove with xa_erase
- Replace idr_destroy with xa_destroy
- Updated the include to use xarray
No core functional changes, just modernized the code to a new API.
Signed-off-by: Neel Bullywon <neelb2403@gmail.com>
---
drivers/staging/greybus/uart.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 5cece0a6606f..8bd6bf0a57a8 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>
@@ -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) {
@@ -362,7 +362,7 @@ static int alloc_minor(struct gb_tty *gb_tty)
int minor;
mutex_lock(&table_lock);
- minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
+ minor = 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;
@@ -375,7 +375,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 +984,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.44.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] staging: greybus: uart: migrated from IDR to XArray API
2026-02-04 4:38 [PATCH] staging: greybus: uart: migrated from IDR to XArray API Neel Bullywon
@ 2026-02-07 13:25 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-07 13:25 UTC (permalink / raw)
To: Neel Bullywon
Cc: David Lin, Johan Hovold, Alex Elder, greybus-dev, linux-staging,
linux-kernel
On Tue, Feb 03, 2026 at 11:38:02PM -0500, Neel Bullywon wrote:
> Replaced the IDR API with the XArray API for managing TTY minor numbers.
> This addresses the checkpatch warning about DEFINE_IDR being deprecated.
While I understand that some people might feel that xarrays are the
bees-knees, for something "simple" like an idr, it's overkill, right?
This is "just" a unique integer that is used for a device name, leaving
it as an idr should be just fine as there is no performance or storage
issues with it as-is.
So while I'm all for using new apis for new code, unless all usages of
idr is going to be replaced in the kernel with xarray, I don't really
feel that this is needed to be done here, sorry.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-07 13:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-04 4:38 [PATCH] staging: greybus: uart: migrated from IDR to XArray API Neel Bullywon
2026-02-07 13:25 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox