]> www.infradead.org Git - users/willy/xarray.git/commitdiff
greybus: Convert uart tty_minors to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 22:21:05 +0000 (17:21 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:18 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/staging/greybus/uart.c

index b3bffe91ae99b238ca007c0c499d6c1fb7dadd60..0b5b0488785dfb9efeb5186612ccb1c9a34ab16a 100644 (file)
@@ -75,7 +75,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)
@@ -353,7 +353,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) {
@@ -370,14 +370,14 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
 
 static int alloc_minor(struct gb_tty *gb_tty)
 {
-       int minor;
+       int err;
 
        mutex_lock(&table_lock);
-       minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
+       err = xa_alloc(&tty_minors, &gb_tty->minor, gb_tty,
+                       XA_LIMIT(0, GB_NUM_MINORS - 1), GFP_KERNEL);
        mutex_unlock(&table_lock);
-       if (minor >= 0)
-               gb_tty->minor = minor;
-       return minor;
+
+       return err;
 }
 
 static void release_minor(struct gb_tty *gb_tty)
@@ -386,7 +386,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);
 }
 
@@ -1009,7 +1009,6 @@ static void gb_tty_exit(void)
 {
        tty_unregister_driver(gb_tty_driver);
        put_tty_driver(gb_tty_driver);
-       idr_destroy(&tty_minors);
 }
 
 static const struct gbphy_device_id gb_uart_id_table[] = {