Re: [PATCH] tty: serial: add missing clk_put()

From: Dmitry Baryshkov
Date: Tue Jul 18 2023 - 04:40:09 EST


On 18/07/2023 10:55, sunran001@xxxxxxxxxx wrote:
This patch fixes the following Coccinelle error:

./drivers/tty/serial/bcm63xx_uart.c:854:2-8: ERROR: missing clk_put;
clk_get on line 849 and execution via conditional on line 853

Signed-off-by: Ran Sun <sunran001@xxxxxxxxxx>
---
 drivers/tty/serial/bcm63xx_uart.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tty/serial/bcm63xx_uart.c b/drivers/tty/serial/bcm63xx_uart.c
index 55e82d0bf92d..7353b683952d 100644
--- a/drivers/tty/serial/bcm63xx_uart.c
+++ b/drivers/tty/serial/bcm63xx_uart.c
@@ -851,6 +851,7 @@ static int bcm_uart_probe(struct platform_device *pdev)
         clk = of_clk_get(pdev->dev.of_node, 0);

     if (IS_ERR(clk))
+        clk_put(clk);

No!

First, calling clk_put() on the error pointer is incorrect. This will throw a warning in __clk_put(), but generally passing an error pointer to another function can cause different kinds of breakage.

Second, you have added the line, but this also moved the return statement out of the if condition. This way all bcm_uart_probe() calls will end up with -ENODEV return value.

Please stop blindly fixing the coccinelle warnings. Take care to read and understand the code.

         return -ENODEV;

     port->iotype = UPIO_MEM;

--
With best wishes
Dmitry