Skip to contentSkip to conversation

memory: stm32_omm: Fix error handling bugs

PATCH Applied Dan Carpenter 2 participants 4 messages May 9, 2025 – May 12, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover memory: stm32_omm: Fix error handling bugs

These are a couple bugs which were detected using the Smatch static checker.

Dan Carpenter (2):
memory: stm32_omm: Fix error handling in stm32_omm_configure()
memory: stm32_omm: Fix NULL vs IS_ERR() check in probe()

 drivers/memory/stm32_omm.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/2 memory: stm32_omm: Fix error handling in stm32_omm_configure()

There are two error handling bugs in the stm32_omm_configure() function.
1) The error code needs to be set if clk_get_rate() fails.
2) If devm_reset_control_get_exclusive() then call pm_runtime_put_sync_suspend() before returning.

Fixes 8181d061dcff ("memory: Add STM32 Octo Memory Manager driver")
---
 drivers/memory/stm32_omm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/memory/stm32_omm.c +5 -2
index 166baed0738a..fa0f75e4a6e8 100644
@@ -222,6 +222,7 @@ static int stm32_omm_configure(struct device *dev)
 		clk_rate = clk_get_rate(omm->clk_bulk[i].clk);
 		if (!clk_rate) {
 			dev_err(dev, "Invalid clock rate\n");
+			ret = -EINVAL;
 			goto error;
 		}
 
@@ -230,8 +231,10 @@ static int stm32_omm_configure(struct device *dev)
 	}
 
 	rstc = devm_reset_control_get_exclusive(dev, "omm");
-	if (IS_ERR(rstc))
-		return dev_err_probe(dev, PTR_ERR(rstc), "reset get failed\n");
+	if (IS_ERR(rstc)) {
+		ret = dev_err_probe(dev, PTR_ERR(rstc), "reset get failed\n");
+		goto error;
+	}
 
 	reset_control_assert(rstc);
 	udelay(2);
Signature · 1 line
2.47.2
#2 lore raw

PATCH 2/2 memory: stm32_omm: Fix NULL vs IS_ERR() check in probe()

In reply to Dan Carpenter

The platform_get_resource_byname() function returns NULL on error. It doesn't return error pointers. Update the check to match.

Fixes 8181d061dcff ("memory: Add STM32 Octo Memory Manager driver")
---
 drivers/memory/stm32_omm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/memory/stm32_omm.c +2 -2
index fa0f75e4a6e8..c8de785401f2 100644
@@ -320,8 +320,8 @@ static int stm32_omm_probe(struct platform_device *pdev)
 		return PTR_ERR(omm->io_base);
 
 	omm->mm_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "memory_map");
-	if (IS_ERR(omm->mm_res))
-		return PTR_ERR(omm->mm_res);
+	if (!omm->mm_res)
+		return -ENODEV;
 
 	/* check child's access */
 	for_each_child_of_node_scoped(dev->of_node, child) {
Signature · 1 line
2.47.2
#3 lore raw
In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

These are a couple bugs which were detected using the Smatch static checker.

Dan Carpenter (2):
memory: stm32_omm: Fix error handling in stm32_omm_configure()
memory: stm32_omm: Fix NULL vs IS_ERR() check in probe()

[...]

Applied, thanks!

[1/2] memory: stm32_omm: Fix error handling in stm32_omm_configure()

      https://git.kernel.org/krzk/linux-mem-ctrl/c/d44eeb20d9bedce11297a09628ba5dd39db236be
[2/2] memory: stm32_omm: Fix NULL vs IS_ERR() check in probe()
      https://git.kernel.org/krzk/linux-mem-ctrl/c/0169a24036848cf18205301673259bb6879eef97

Best regards,

Signature · 1 line
Krzysztof Kozlowski <[email protected]>