diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c index 065bf21d95eb..fefa017ff8a6 100644 --- a/drivers/tty/serial/msm_serial.c +++ b/drivers/tty/serial/msm_serial.c @@ -1778,14 +1778,17 @@ static int msm_serial_probe(struct platform_device *pdev) struct uart_port *port; const struct of_device_id *id; int irq, line; + bool flag = false; if (pdev->dev.of_node) line = of_alias_get_id(pdev->dev.of_node, "serial"); else line = pdev->id; - if (line < 0) + if (line < 0) { + flag = true; line = atomic_inc_return(&msm_uart_next_id) - 1; + } if (unlikely(line < 0 || line >= UART_NR)) return -ENXIO; @@ -1803,26 +1806,40 @@ static int msm_serial_probe(struct platform_device *pdev) msm_port->is_uartdm = 0; msm_port->clk = devm_clk_get(&pdev->dev, "core"); - if (IS_ERR(msm_port->clk)) + if (IS_ERR(msm_port->clk)) { + if (flag) + atomic_dec(&msm_uart_next_id); return PTR_ERR(msm_port->clk); + } if (msm_port->is_uartdm) { msm_port->pclk = devm_clk_get(&pdev->dev, "iface"); - if (IS_ERR(msm_port->pclk)) + if (IS_ERR(msm_port->pclk)) { + if (flag) + atomic_dec(&msm_uart_next_id); return PTR_ERR(msm_port->pclk); + } } port->uartclk = clk_get_rate(msm_port->clk); dev_info(&pdev->dev, "uartclk = %d\n", port->uartclk); resource = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (unlikely(!resource)) + if (unlikely(!resource)) { + if (flag) + atomic_dec(&msm_uart_next_id); return -ENXIO; + } + port->mapbase = resource->start; irq = platform_get_irq(pdev, 0); - if (unlikely(irq < 0)) + if (unlikely(irq < 0)) { + if (flag) + atomic_dec(&msm_uart_next_id); return -ENXIO; + } + port->irq = irq; platform_set_drvdata(pdev, port);