]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/tty/serial/fsl_lpuart.c
Merge tag 'exynos-drm-fixes-for-v5.6-rc5-v2' of git://git.kernel.org/pub/scm/linux...
[linux.git] / drivers / tty / serial / fsl_lpuart.c
index 91e2805e64416f5e54d4bbe52ee6594e0cad8e45..c31b8f3db6bf681b3df61d89431c8a957688d47d 100644 (file)
@@ -264,6 +264,7 @@ struct lpuart_port {
        int                     rx_dma_rng_buf_len;
        unsigned int            dma_tx_nents;
        wait_queue_head_t       dma_wait;
+       bool                    id_allocated;
 };
 
 struct lpuart_soc_data {
@@ -2390,6 +2391,8 @@ static int __init lpuart32_imx_early_console_setup(struct earlycon_device *devic
 OF_EARLYCON_DECLARE(lpuart, "fsl,vf610-lpuart", lpuart_early_console_setup);
 OF_EARLYCON_DECLARE(lpuart32, "fsl,ls1021a-lpuart", lpuart32_early_console_setup);
 OF_EARLYCON_DECLARE(lpuart32, "fsl,imx7ulp-lpuart", lpuart32_imx_early_console_setup);
+EARLYCON_DECLARE(lpuart, lpuart_early_console_setup);
+EARLYCON_DECLARE(lpuart32, lpuart32_early_console_setup);
 
 #define LPUART_CONSOLE (&lpuart_console)
 #define LPUART32_CONSOLE       (&lpuart32_console)
@@ -2420,19 +2423,6 @@ static int lpuart_probe(struct platform_device *pdev)
        if (!sport)
                return -ENOMEM;
 
-       ret = of_alias_get_id(np, "serial");
-       if (ret < 0) {
-               ret = ida_simple_get(&fsl_lpuart_ida, 0, UART_NR, GFP_KERNEL);
-               if (ret < 0) {
-                       dev_err(&pdev->dev, "port line is full, add device failed\n");
-                       return ret;
-               }
-       }
-       if (ret >= ARRAY_SIZE(lpuart_ports)) {
-               dev_err(&pdev->dev, "serial%d out of range\n", ret);
-               return -EINVAL;
-       }
-       sport->port.line = ret;
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        sport->port.membase = devm_ioremap_resource(&pdev->dev, res);
        if (IS_ERR(sport->port.membase))
@@ -2477,9 +2467,25 @@ static int lpuart_probe(struct platform_device *pdev)
                }
        }
 
+       ret = of_alias_get_id(np, "serial");
+       if (ret < 0) {
+               ret = ida_simple_get(&fsl_lpuart_ida, 0, UART_NR, GFP_KERNEL);
+               if (ret < 0) {
+                       dev_err(&pdev->dev, "port line is full, add device failed\n");
+                       return ret;
+               }
+               sport->id_allocated = true;
+       }
+       if (ret >= ARRAY_SIZE(lpuart_ports)) {
+               dev_err(&pdev->dev, "serial%d out of range\n", ret);
+               ret = -EINVAL;
+               goto failed_out_of_range;
+       }
+       sport->port.line = ret;
+
        ret = lpuart_enable_clks(sport);
        if (ret)
-               return ret;
+               goto failed_clock_enable;
        sport->port.uartclk = lpuart_get_baud_clk_rate(sport);
 
        lpuart_ports[sport->port.line] = sport;
@@ -2529,6 +2535,10 @@ static int lpuart_probe(struct platform_device *pdev)
 failed_attach_port:
 failed_irq_request:
        lpuart_disable_clks(sport);
+failed_clock_enable:
+failed_out_of_range:
+       if (sport->id_allocated)
+               ida_simple_remove(&fsl_lpuart_ida, sport->port.line);
        return ret;
 }
 
@@ -2538,7 +2548,8 @@ static int lpuart_remove(struct platform_device *pdev)
 
        uart_remove_one_port(&lpuart_reg, &sport->port);
 
-       ida_simple_remove(&fsl_lpuart_ida, sport->port.line);
+       if (sport->id_allocated)
+               ida_simple_remove(&fsl_lpuart_ida, sport->port.line);
 
        lpuart_disable_clks(sport);