[PATCH v2 3/3] clk: Prevent memory leak on error

Andrew Goodbody andrew.goodbody at linaro.org
Fri Nov 21 18:34:33 CET 2025


In clk_set_default_rates() memory is allocated to store the clock rates
that are read. Direct returns fail to free this memory leading to a
memory leak so instead use 'goto fail;' which will then perform the free
before exiting the function.

Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
---
 drivers/clk/clk-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index a72a67d75a165c2d98bb702888e848f6b075fc7d..bf9f104193573918ad2efbce2bd2578948e44811 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -338,7 +338,7 @@ static int clk_set_default_rates(struct udevice *dev,
 				continue;
 			}
 
-			return ret;
+			goto fail;
 		}
 
 		/* This is clk provider device trying to program itself

-- 
2.47.3



More information about the U-Boot mailing list