]> www.infradead.org Git - users/willy/xarray.git/commitdiff
usb/serial: Convert serial_minors to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 23:52:49 +0000 (18:52 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 03:39:58 +0000 (23:39 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/usb/serial/usb-serial.c

index a3179fea38c87b51ca54c85635eff0acb86a8d61..7fc34deb5aeb5f5a3ad01d11d36b02203954cd16 100644 (file)
@@ -49,7 +49,7 @@
    drivers depend on it.
 */
 
-static DEFINE_IDR(serial_minors);
+static DEFINE_XARRAY_ALLOC(serial_minors);
 static DEFINE_MUTEX(table_lock);
 static LIST_HEAD(usb_serial_driver_list);
 
@@ -64,7 +64,7 @@ struct usb_serial_port *usb_serial_port_get_by_minor(unsigned minor)
        struct usb_serial_port *port;
 
        mutex_lock(&table_lock);
-       port = idr_find(&serial_minors, minor);
+       port = xa_load(&serial_minors, minor);
        if (!port)
                goto exit;
 
@@ -85,18 +85,18 @@ static int allocate_minors(struct usb_serial *serial, int num_ports)
 {
        struct usb_serial_port *port;
        unsigned int i, j;
-       int minor;
+       int err;
 
        dev_dbg(&serial->interface->dev, "%s %d\n", __func__, num_ports);
 
        mutex_lock(&table_lock);
        for (i = 0; i < num_ports; ++i) {
                port = serial->port[i];
-               minor = idr_alloc(&serial_minors, port, 0,
-                                       USB_SERIAL_TTY_MINORS, GFP_KERNEL);
-               if (minor < 0)
+               err = xa_alloc(&serial_minors, &port->minor, port,
+                               XA_LIMIT(0, USB_SERIAL_TTY_MINORS - 1),
+                               GFP_KERNEL);
+               if (err < 0)
                        goto error;
-               port->minor = minor;
                port->port_number = i;
        }
        serial->minors_reserved = 1;
@@ -105,9 +105,9 @@ static int allocate_minors(struct usb_serial *serial, int num_ports)
 error:
        /* unwind the already allocated minors */
        for (j = 0; j < i; ++j)
-               idr_remove(&serial_minors, serial->port[j]->minor);
+               xa_erase(&serial_minors, serial->port[j]->minor);
        mutex_unlock(&table_lock);
-       return minor;
+       return err;
 }
 
 static void release_minors(struct usb_serial *serial)
@@ -116,7 +116,7 @@ static void release_minors(struct usb_serial *serial)
 
        mutex_lock(&table_lock);
        for (i = 0; i < serial->num_ports; ++i)
-               idr_remove(&serial_minors, serial->port[i]->minor);
+               xa_erase(&serial_minors, serial->port[i]->minor);
        mutex_unlock(&table_lock);
        serial->minors_reserved = 0;
 }
@@ -1274,7 +1274,6 @@ static void __exit usb_serial_exit(void)
        tty_unregister_driver(usb_serial_tty_driver);
        put_tty_driver(usb_serial_tty_driver);
        bus_unregister(&usb_serial_bus_type);
-       idr_destroy(&serial_minors);
 }