[PATCH 4/4] usb/serial: Convert serial_minors to XArray

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Matthew Wilcox <willy@xxxxxxxxxxxxx>
---
 drivers/usb/serial/usb-serial.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 7e89efbf2c28..ad8b9cb17ca5 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -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;
 }
@@ -1271,7 +1271,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);
 }
 
 
-- 
2.20.1




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux