Skip to contentSkip to conversation

staging: greybus: uart: replace DEFINE_IDR with DEFINE_XARRAY_ALLOC

PATCH In review Rahul Joshi 2 participants 2 messages Mar 11 – Mar 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: greybus: uart: replace DEFINE_IDR with DEFINE_XARRAY_ALLOC

DEFINE_IDR is deprecated in favour of DEFINE_XARRAY_ALLOC. Replace the tty_minors IDR with an XArray and update all call sites:

idr_alloc() -> xa_alloc()
idr_find() -> xa_load()
idr_remove() -> xa_erase()
idr_destroy() -> xa_destroy()

Also remove the now-unused <linux/idr.h> include and add <linux/xarray.h>.

---
 drivers/staging/greybus/uart.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/staging/greybus/uart.c +14 -10
index 7d060b4cd33d..bed3f35a6ec2 100644
@@ -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) {
@@ -359,14 +359,18 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
 
 static int alloc_minor(struct gb_tty *gb_tty)
 {
-	int minor;
+	int retval;
+	u32 index;
 
 	mutex_lock(&table_lock);
-	minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
+	retval = xa_alloc(&tty_minors, &index, gb_tty,
+			  XA_LIMIT(0, GB_NUM_MINORS - 1), GFP_KERNEL);
 	mutex_unlock(&table_lock);
-	if (minor >= 0)
-		gb_tty->minor = minor;
-	return minor;
+	if (retval < 0)
+		return retval;
+
+	gb_tty->minor = index;
+	return index;
 }
 
 static void release_minor(struct gb_tty *gb_tty)
@@ -375,7 +379,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 +988,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[] = {
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 8 lines · Rahul Joshi

DEFINE_IDR is deprecated in favour of DEFINE_XARRAY_ALLOC. Replace the tty_minors IDR with an XArray and update all call sites:

idr_alloc() -> xa_alloc()
idr_find() -> xa_load()
idr_remove() -> xa_erase()
idr_destroy() -> xa_destroy()

Quoted 7 lines

Also remove the now-unused <linux/idr.h> include and add <linux/xarray.h>.

---
 drivers/staging/greybus/uart.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

I am pretty sure I have rejected this same patch multiple times in the past. Please see the mailing list archives for why.

thanks,

greg k-h