From 2c57ec46e1f9e2003bf97e4051f4447c756ec1a8 Mon Sep 17 00:00:00 2001 From: Yue Liu Date: Mon, 6 Dec 2021 13:35:44 +0800 Subject: [PATCH] msm_serial: msm_uart_next_id decrease when probe failed When the msm_serial driver defer probed, if msm_uart_next_id increased at the beginning of probe, should decreased when probe failed. Change-Id: I8a2594afca17c4ab5fef78da822ffdf39377d0bb Signed-off-by: Yue Liu --- drivers/tty/serial/msm_serial.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) 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);