Skip to contentSkip to conversation

counter: interrupt-cnt: use devm_mutex_init()

PATCH In review Stepan Ionichev 3 participants 3 messages May 25 – May 27

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

PATCH v2 1/1 counter: interrupt-cnt: use devm_mutex_init()

interrupt_cnt_probe() calls mutex_init() but neither this driver nor the counter core issues a matching mutex_destroy() on unbind, which leaks the lock debug state when CONFIG_DEBUG_MUTEXES is enabled.

Switch to devm_mutex_init() so the mutex is torn down in the same devm scope it was set up in.

Fixes a55ebd47f21f ("counter: add IRQ or GPIO based counter")

---
v2:
- Add Fixes tag and clarify the leak is only visible under CONFIG_DEBUG_MUTEXES (William, Joshua)
- Add Reviewed-by from Joshua

v1: https://lore.kernel.org/all/[email protected]/

 drivers/counter/interrupt-cnt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/counter/interrupt-cnt.c +3 -1
index e6100b5fb..cd475382a 100644
@@ -233,7 +233,9 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	mutex_init(&priv->lock);
+	ret = devm_mutex_init(dev, &priv->lock);
+	if (ret)
+		return ret;
 
 	ret = devm_counter_add(dev, counter);
 	if (ret < 0)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 9 lines · Stepan Ionichev

interrupt_cnt_probe() calls mutex_init() but neither this driver nor the counter core issues a matching mutex_destroy() on unbind, which leaks the lock debug state when CONFIG_DEBUG_MUTEXES is enabled.

Switch to devm_mutex_init() so the mutex is torn down in the same devm scope it was set up in.

Fixes a55ebd47f21f ("counter: add IRQ or GPIO based counter")

The mutex_init() code was added in 7351312632e8 ("counter:
interrupt-cnt: Protect enable/disable OPs with mutex"), so the Fixes tag should refer to that commit.

William Breathitt Gray

maintainer
#2 lore raw
Quoted 6 lines · On Wed, 27 May 2026 15:56:31 +0900 William Breathitt Gray <[email protected]>…
Quoted 5 lines · Stepan Ionichev

interrupt_cnt_probe() calls mutex_init() but neither this driver nor the counter core issues a matching mutex_destroy() on unbind, which leaks the lock debug state when CONFIG_DEBUG_MUTEXES is enabled.

Quoted 9 lines
Quoted 4 lines

Switch to devm_mutex_init() so the mutex is torn down in the same devm scope it was set up in.

Fixes a55ebd47f21f ("counter: add IRQ or GPIO based counter")

The mutex_init() code was added in 7351312632e8 ("counter:
interrupt-cnt: Protect enable/disable OPs with mutex"), so the Fixes tag should refer to that commit.

Not a fix. For a long time it was common to take the view that
mutex_destroy() was only useful if you had marginally complex lifetime handling in a driver and it might help detect bugs.

Now devm_mutex_init() makes it easier to do, the barrier to deciding to have that protection is reduced, so we apply it to more drivers (for IIO I now ask for this always). That doesn't make it a fix as such, more of an update to modern approaches and definitely not suitable for the backports that will likely cause. So I'd drop the fixes tag.

Jonathan

Quoted 2 lines

William Breathitt Gray