Skip to contentSkip to conversation

pinctrl: stm32: fix hwspinlock resource leak in probe function

PATCH In review Haotian Zhang 3 participants 3 messages Oct 29, 2025

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

PATCH 1/1 pinctrl: stm32: fix hwspinlock resource leak in probe function

In stm32_pctl_probe(), hwspin_lock_request_specific() is called to request a hwspinlock, but the acquired lock is not freed on multiple error paths after this call. This causes resource leakage when the function fails to initialize properly.

Use devm_hwspin_lock_request_specific() instead of hwspin_lock_request_specific() to automatically manage the hwspinlock resource lifecycle.

Fixes 97cfb6cd34f2 ("pinctrl: stm32: protect configuration registers with a hwspinlock")
---
 drivers/pinctrl/stm32/pinctrl-stm32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/stm32/pinctrl-stm32.c +1 -1
index 823c8fe758e2..d9a2d20a7e6b 100644
@@ -1671,7 +1671,7 @@ int stm32_pctl_probe(struct platform_device *pdev)
 		if (hwlock_id == -EPROBE_DEFER)
 			return hwlock_id;
 	} else {
-		pctl->hwlock = hwspin_lock_request_specific(hwlock_id);
+		pctl->hwlock = devm_hwspin_lock_request_specific(dev, hwlock_id);
 	}
 
 	spin_lock_init(&pctl->irqmux_lock);
Signature · 1 line
2.50.1.windows.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Haotian Zhang

In stm32_pctl_probe(), hwspin_lock_request_specific() is called to request a hwspinlock, but the acquired lock is not freed on multiple error paths after this call. This causes resource leakage when the function fails to initialize properly.

Use devm_hwspin_lock_request_specific() instead of hwspin_lock_request_specific() to automatically manage the hwspinlock resource lifecycle.

Fixes 97cfb6cd34f2 ("pinctrl: stm32: protect configuration registers with a hwspinlock")

---
 drivers/pinctrl/stm32/pinctrl-stm32.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/stm32/pinctrl-stm32.c +1 -1
index 823c8fe758e2..d9a2d20a7e6b 100644
@@ -1671,7 +1671,7 @@ int stm32_pctl_probe(struct platform_device *pdev)
                 if (hwlock_id == -EPROBE_DEFER)
                         return hwlock_id;
         } else {
-               pctl->hwlock = hwspin_lock_request_specific(hwlock_id);
+               pctl->hwlock = devm_hwspin_lock_request_specific(dev, hwlock_id);
         }
Quoted 2 lines


        spin_lock_init(&pctl->irqmux_lock);

Thanks!
Antonio

#2 lore raw
In reply to Haotian Zhang
Quoted 11 lines · Haotian Zhang

In stm32_pctl_probe(), hwspin_lock_request_specific() is called to request a hwspinlock, but the acquired lock is not freed on multiple error paths after this call. This causes resource leakage when the function fails to initialize properly.

Use devm_hwspin_lock_request_specific() instead of hwspin_lock_request_specific() to automatically manage the hwspinlock resource lifecycle.

Fixes 97cfb6cd34f2 ("pinctrl: stm32: protect configuration registers with a hwspinlock")

Patch applied!

Yours,
Linus Walleij