[PATCH] serial: bcm63xx-uart: silence false positive coccinelle warning on clk_put

Pei Xiao <[email protected]> Thu, 23 Jul 2026 14:34:09 +0800
Newsgroups org.kernel.vger.linux-serial,org.kernel.vger.linux-kernel
Message-ID <604886147edb67c3ed85b192eb3f7a4a6dd0f0ac.1784788388.git.xiaopei01@kylinos.cn>
Coccinelle warns about missing clk_put on the error path after clk_get,
but the error path returns with an ERR_PTR where clk_put must not be
called.  Restructure into a single if block so the logic is clear to
silence false positive coccinelle warning.

Commit 580d952e44de ("tty: serial: bcm63xx: fix missing clk_put() in
bcm63xx_uart") previously tried to fix this same warning by adding a
clk_put, which was reverted because it was wrong.
Prevent anyone from making the same mistake again.

Signed-off-by: Pei Xiao <[email protected]>
---
 drivers/tty/serial/bcm63xx_uart.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/bcm63xx_uart.c b/drivers/tty/serial/bcm63xx_uart.c
index 544695cb184c..1754cf252b7c 100644
--- a/drivers/tty/serial/bcm63xx_uart.c
+++ b/drivers/tty/serial/bcm63xx_uart.c
@@ -838,11 +838,12 @@ static int bcm_uart_probe(struct platform_device *pdev)
 	port->irq = ret;
 
 	clk = clk_get(&pdev->dev, "refclk");
-	if (IS_ERR(clk) && pdev->dev.of_node)
-		clk = of_clk_get(pdev->dev.of_node, 0);
-
-	if (IS_ERR(clk))
-		return -ENODEV;
+	if (IS_ERR(clk)) {
+		if (pdev->dev.of_node)
+			clk = of_clk_get(pdev->dev.of_node, 0);
+		if (IS_ERR(clk))
+			return -ENODEV;
+	}
 
 	port->iotype = UPIO_MEM;
 	port->ops = &bcm_uart_ops;
-- 
2.25.1