]> www.infradead.org Git - users/willy/xarray.git/commitdiff
mps2-uart: Convert ports_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Thu, 14 Mar 2019 22:33:15 +0000 (18:33 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:19 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/tty/serial/mps2-uart.c

index 587b42f754cb8d2ccbb2c38334c7373b23b04aa1..8df4ffd516c0a64e48c64e9d0a05f5dc23dc28f8 100644 (file)
@@ -22,7 +22,7 @@
 #include <linux/serial_core.h>
 #include <linux/tty_flip.h>
 #include <linux/types.h>
-#include <linux/idr.h>
+#include <linux/xarray.h>
 
 #define SERIAL_NAME    "ttyMPS"
 #define DRIVER_NAME    "mps2-uart"
@@ -429,7 +429,7 @@ static const struct uart_ops mps2_uart_pops = {
        .verify_port = mps2_uart_verify_port,
 };
 
-static DEFINE_IDR(ports_idr);
+static DEFINE_XARRAY_ALLOC(ports);
 
 #ifdef CONFIG_SERIAL_MPS2_UART_CONSOLE
 static void mps2_uart_console_putchar(struct uart_port *port, int ch)
@@ -442,7 +442,7 @@ static void mps2_uart_console_putchar(struct uart_port *port, int ch)
 
 static void mps2_uart_console_write(struct console *co, const char *s, unsigned int cnt)
 {
-       struct mps2_uart_port *mps_port = idr_find(&ports_idr, co->index);
+       struct mps2_uart_port *mps_port = xa_load(&ports, co->index);
        struct uart_port *port = &mps_port->port;
 
        uart_console_write(port, s, cnt, mps2_uart_console_putchar);
@@ -459,7 +459,7 @@ static int mps2_uart_console_setup(struct console *co, char *options)
        if (co->index < 0 || co->index >= MPS2_MAX_PORTS)
                return -ENODEV;
 
-       mps_port = idr_find(&ports_idr, co->index);
+       mps_port = xa_load(&ports, co->index);
 
        if (!mps_port)
                return -ENODEV;
@@ -527,27 +527,28 @@ static int mps2_of_get_port(struct platform_device *pdev,
                            struct mps2_uart_port *mps_port)
 {
        struct device_node *np = pdev->dev.of_node;
-       int id;
+       int id, err;
 
        if (!np)
                return -ENODEV;
 
        id = of_alias_get_id(np, "serial");
 
-       if (id < 0)
-               id = idr_alloc_cyclic(&ports_idr, (void *)mps_port, 0, MPS2_MAX_PORTS, GFP_KERNEL);
-       else
-               id = idr_alloc(&ports_idr, (void *)mps_port, id, MPS2_MAX_PORTS, GFP_KERNEL);
+       if (id < 0) {
+               err = xa_alloc(&ports, &mps_port->port.line, mps_port,
+                               XA_LIMIT(0, MPS2_MAX_PORTS - 1), GFP_KERNEL);
+       } else {
+               mps_port->port.line = id;
+               err = xa_insert(&ports, id, mps_port, GFP_KERNEL);
+       }
 
-       if (id < 0)
-               return id;
+       if (err < 0)
+               return err;
 
        /* Only combined irq is presesnt */
        if (platform_irq_count(pdev) == 1)
                mps_port->flags |= UART_PORT_COMBINED_IRQ;
 
-       mps_port->port.line = id;
-
        return 0;
 }