From: Matthew Wilcox Date: Thu, 14 Mar 2019 22:33:15 +0000 (-0400) Subject: mps2-uart: Convert ports_idr to XArray X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=836fd255597fed27719c077fffcd64d0324ca8c0;p=users%2Fwilly%2Fxarray.git mps2-uart: Convert ports_idr to XArray Signed-off-by: Matthew Wilcox --- diff --git a/drivers/tty/serial/mps2-uart.c b/drivers/tty/serial/mps2-uart.c index 587b42f754cb..8df4ffd516c0 100644 --- a/drivers/tty/serial/mps2-uart.c +++ b/drivers/tty/serial/mps2-uart.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #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; }