[PATCH] clk: stm32f4: Return ENOMEM when allocating clock components fails

Zhu Jun zhujun2 at cmss.chinamobile.com
Wed Nov 11 18:31:58 PST 2026


stm32_register_cclk() and stm32_register_aux_clk() return -EINVAL when
allocating a gate or mux fails. These paths indicate memory exhaustion,
not an invalid clock configuration.

Return -ENOMEM for those allocation failures. Keep -EINVAL for an
auxiliary clock with neither a gate nor a mux.

OpenAI Codex assisted with analysis and patch preparation.

Fixes: 4261a881cfee ("clk: stm32f4: Add RTC clock")
Fixes: daf2d117cbca ("clk: stm32f4: Add lcd-tft clock")
Signed-off-by: Zhu Jun <zhujun2 at cmss.chinamobile.com>
---
 drivers/clk/clk-stm32f4.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk-stm32f4.c b/drivers/clk/clk-stm32f4.c
index 6603d4815514..bf78fd1744c3 100644
--- a/drivers/clk/clk-stm32f4.c
+++ b/drivers/clk/clk-stm32f4.c
@@ -1204,14 +1204,14 @@ static struct clk_hw *stm32_register_cclk(struct device *dev, const char *name,
 
 	gate = kzalloc_obj(*gate);
 	if (!gate) {
-		hw = ERR_PTR(-EINVAL);
+		hw = ERR_PTR(-ENOMEM);
 		goto fail;
 	}
 
 	mux = kzalloc_obj(*mux);
 	if (!mux) {
 		kfree(gate);
-		hw = ERR_PTR(-EINVAL);
+		hw = ERR_PTR(-ENOMEM);
 		goto fail;
 	}
 
@@ -1778,7 +1778,7 @@ static struct clk_hw *stm32_register_aux_clk(const char *name,
 	if (offset_gate != NO_GATE) {
 		gate = kzalloc_obj(*gate);
 		if (!gate) {
-			hw = ERR_PTR(-EINVAL);
+			hw = ERR_PTR(-ENOMEM);
 			goto fail;
 		}
 
@@ -1793,7 +1793,7 @@ static struct clk_hw *stm32_register_aux_clk(const char *name,
 	if (offset_mux != NO_MUX) {
 		mux = kzalloc_obj(*mux);
 		if (!mux) {
-			hw = ERR_PTR(-EINVAL);
+			hw = ERR_PTR(-ENOMEM);
 			goto fail;
 		}
 
-- 
2.51.0






More information about the linux-arm-kernel mailing list