diff mbox series

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

Message ID 20190318211713.3462-5-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Convert USB subsystem to XArray | expand

Commit Message

Matthew Wilcox March 18, 2019, 9:17 p.m. UTC
Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/usb/serial/usb-serial.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

Comments

Greg KH March 19, 2019, 6:14 a.m. UTC | #1
On Mon, Mar 18, 2019 at 02:17:13PM -0700, Matthew Wilcox wrote:
> Signed-off-by: Matthew Wilcox <willy@infradead.org>
> ---
>  drivers/usb/serial/usb-serial.c | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)

I really do not like taking patches without any changelog text at all :(
Matthew Wilcox March 19, 2019, 11:35 a.m. UTC | #2
On Tue, Mar 19, 2019 at 07:14:09AM +0100, Greg KH wrote:
> On Mon, Mar 18, 2019 at 02:17:13PM -0700, Matthew Wilcox wrote:
> > Signed-off-by: Matthew Wilcox <willy@infradead.org>
> > ---
> >  drivers/usb/serial/usb-serial.c | 21 ++++++++++-----------
> >  1 file changed, 10 insertions(+), 11 deletions(-)
> 
> I really do not like taking patches without any changelog text at all :(

I'm really not sure what to say.  Something extolling the superiority
of the new API?  I've got 279 patches here and some of them are really
just 1:1 replacements like this one.

What would you want to read if you came across this patch in git log
in five years time?
Oliver Neukum March 19, 2019, 11:36 a.m. UTC | #3
On Di, 2019-03-19 at 04:35 -0700, Matthew Wilcox wrote:
> On Tue, Mar 19, 2019 at 07:14:09AM +0100, Greg KH wrote:
> > On Mon, Mar 18, 2019 at 02:17:13PM -0700, Matthew Wilcox wrote:
> > > Signed-off-by: Matthew Wilcox <willy@infradead.org>
> > > ---
> > >  drivers/usb/serial/usb-serial.c | 21 ++++++++++-----------
> > >  1 file changed, 10 insertions(+), 11 deletions(-)
> > 
> > I really do not like taking patches without any changelog text at all :(
> 
> I'm really not sure what to say.  Something extolling the superiority
> of the new API?

Yes. Something like

XARRAy is a replacement for radix trees. Convert this subsystem.
Part of a project for the whole kernel.

	Regards
		Oliver
Greg KH March 19, 2019, 12:11 p.m. UTC | #4
On Tue, Mar 19, 2019 at 12:36:21PM +0100, Oliver Neukum wrote:
> On Di, 2019-03-19 at 04:35 -0700, Matthew Wilcox wrote:
> > On Tue, Mar 19, 2019 at 07:14:09AM +0100, Greg KH wrote:
> > > On Mon, Mar 18, 2019 at 02:17:13PM -0700, Matthew Wilcox wrote:
> > > > Signed-off-by: Matthew Wilcox <willy@infradead.org>
> > > > ---
> > > >  drivers/usb/serial/usb-serial.c | 21 ++++++++++-----------
> > > >  1 file changed, 10 insertions(+), 11 deletions(-)
> > > 
> > > I really do not like taking patches without any changelog text at all :(
> > 
> > I'm really not sure what to say.  Something extolling the superiority
> > of the new API?
> 
> Yes. Something like
> 
> XARRAy is a replacement for radix trees. Convert this subsystem.
> Part of a project for the whole kernel.

Yes, that's perfect.  Matthew, just add it to a script and away you go
:)

thanks,

greg k-h
diff mbox series

Patch

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);
 }