Skip to contentSkip to conversation

counter: ftm-quaddec: use devm_mutex_init()

PATCH Applied Stepan Ionichev 4 participants 7 messages May 25 – May 29

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

PATCH v2 1/1 counter: ftm-quaddec: use devm_mutex_init()

ftm_quaddec_probe() calls mutex_init() but neither the cleanup action nor a remove callback issues a matching mutex_destroy(), 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 a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")

---
v2:
- Add Fixes tag and note that the leak only shows up under CONFIG_DEBUG_MUTEXES (William, applied from the interrupt-cnt thread)

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

 drivers/counter/ftm-quaddec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/counter/ftm-quaddec.c +3 -1
index c47741292..8455f16d6 100644
@@ -292,7 +292,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 	counter->signals = ftm_quaddec_signals;
 	counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);
 
-	mutex_init(&ftm->ftm_quaddec_mutex);
+	ret = devm_mutex_init(&pdev->dev, &ftm->ftm_quaddec_mutex);
+	if (ret)
+		return ret;
 
 	ftm_quaddec_init(ftm);
 
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 37 lines · Stepan Ionichev

ftm_quaddec_probe() calls mutex_init() but neither the cleanup action nor a remove callback issues a matching mutex_destroy(), 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 a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")

---
v2:
- Add Fixes tag and note that the leak only shows up under CONFIG_DEBUG_MUTEXES (William, applied from the interrupt-cnt thread)

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

 drivers/counter/ftm-quaddec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/counter/ftm-quaddec.c +3 -2
index c47741292..8455f16d6 100644
@@ -292,7 +292,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
        counter->signals = ftm_quaddec_signals;
        counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);
 
-       mutex_init(&ftm->ftm_quaddec_mutex);
+       ret = devm_mutex_init(&pdev->dev, &ftm->ftm_quaddec_mutex);
+       if (ret)
+               return ret;
 
        ftm_quaddec_init(ftm);
 
--
Quoted 3 lines

2.43.0

Signature · 3 lines
Kind regards

CJD
maintainer
#2 lore raw
Quoted 7 lines · On Tue, 26 May 2026 12:24:25 +0200 Joshua Crofts <[email protected]>…
Quoted 6 lines · Stepan Ionichev

ftm_quaddec_probe() calls mutex_init() but neither the cleanup action nor a remove callback issues a matching mutex_destroy(), which leaks the lock debug state when CONFIG_DEBUG_MUTEXES is enabled.

Quoted 8 lines
Quoted 8 lines

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

Fixes a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")

---
v2:
- Add Fixes tag and note that the leak only shows up under

It's not a leak as such. All that happens is the 'magic' pointer embedded in the lock is not set NULL. No memory or counters or anything like that leaked in current mainline where the implementation with CONFIG_DEBUG_MUTEXES is

void mutex_destroy(struct mutex *lock)

{
	DEBUG_LOCKS_WARN_ON(mutex_is_locked(lock));
	lock->magic = NULL;
}
Quoted 29 lines
Quoted 23 lines

CONFIG_DEBUG_MUTEXES (William, applied from the interrupt-cnt thread)

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

 drivers/counter/ftm-quaddec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/counter/ftm-quaddec.c +3 -2
index c47741292..8455f16d6 100644
@@ -292,7 +292,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
        counter->signals = ftm_quaddec_signals;
        counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);
 
-       mutex_init(&ftm->ftm_quaddec_mutex);
+       ret = devm_mutex_init(&pdev->dev, &ftm->ftm_quaddec_mutex);
+       if (ret)
+               return ret;
 
        ftm_quaddec_init(ftm);
 
--
Quoted 3 lines

2.43.0

#3 lore raw
Quoted 23 lines · Jonathan Cameron
Quoted 7 lines · On Tue, 26 May 2026 12:24:25 +0200 Joshua Crofts <[email protected]>…
Quoted 6 lines · Stepan Ionichev

ftm_quaddec_probe() calls mutex_init() but neither the cleanup action nor a remove callback issues a matching mutex_destroy(), which leaks the lock debug state when CONFIG_DEBUG_MUTEXES is enabled.

Quoted 8 lines
Quoted 8 lines

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

Fixes a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")

---
v2:
- Add Fixes tag and note that the leak only shows up under

It's not a leak as such. All that happens is the 'magic' pointer embedded in the lock is not set NULL. No memory or counters or anything like that leaked in current mainline where the implementation with CONFIG_DEBUG_MUTEXES is

Quoted 5 lines

void mutex_destroy(struct mutex *lock)

{
	DEBUG_LOCKS_WARN_ON(mutex_is_locked(lock));
	lock->magic = NULL;
}

What is the purpose of the magic pointer? Is it just informational, to catch instances where any attempt to use the mutex occurs after the device memory is freed for example?

William Breathitt Gray

maintainer
#4 lore raw
Quoted 30 lines · On Thu, 28 May 2026 06:52:18 +0900 William Breathitt Gray <[email protected]>…
Quoted 23 lines · Jonathan Cameron
Quoted 7 lines · On Tue, 26 May 2026 12:24:25 +0200 Joshua Crofts <[email protected]>…
Quoted 6 lines · Stepan Ionichev

ftm_quaddec_probe() calls mutex_init() but neither the cleanup action nor a remove callback issues a matching mutex_destroy(), which leaks the lock debug state when CONFIG_DEBUG_MUTEXES is enabled.

Quoted 8 lines
Quoted 8 lines

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

Fixes a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")

---
v2:
- Add Fixes tag and note that the leak only shows up under

It's not a leak as such. All that happens is the 'magic' pointer embedded in the lock is not set NULL. No memory or counters or anything like that leaked in current mainline where the implementation with CONFIG_DEBUG_MUTEXES is

Quoted 5 lines

void mutex_destroy(struct mutex *lock)

{
	DEBUG_LOCKS_WARN_ON(mutex_is_locked(lock));
	lock->magic = NULL;
}  
Quoted 3 lines

What is the purpose of the magic pointer? Is it just informational, to catch instances where any attempt to use the mutex occurs after the device memory is freed for example?

More or less. In some cases the mutex life can be less than the structure containing it.

Quoted 2 lines

William Breathitt Gray

#5 lore raw
Quoted 33 lines · Jonathan Cameron
Quoted 30 lines · On Thu, 28 May 2026 06:52:18 +0900 William Breathitt Gray <[email protected]>…
Quoted 28 lines · Jonathan Cameron
Quoted 7 lines · On Tue, 26 May 2026 12:24:25 +0200 Joshua Crofts <[email protected]>…
Quoted 6 lines · Stepan Ionichev

ftm_quaddec_probe() calls mutex_init() but neither the cleanup action nor a remove callback issues a matching mutex_destroy(), which leaks the lock debug state when CONFIG_DEBUG_MUTEXES is enabled.

Quoted 8 lines
Quoted 8 lines

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

Fixes a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")

---
v2:
- Add Fixes tag and note that the leak only shows up under

It's not a leak as such. All that happens is the 'magic' pointer embedded in the lock is not set NULL. No memory or counters or anything like that leaked in current mainline where the implementation with CONFIG_DEBUG_MUTEXES is

void mutex_destroy(struct mutex *lock)

{
	DEBUG_LOCKS_WARN_ON(mutex_is_locked(lock));
	lock->magic = NULL;
}
Quoted 5 lines
Quoted 3 lines

What is the purpose of the magic pointer? Is it just informational, to catch instances where any attempt to use the mutex occurs after the device memory is freed for example?

More or less. In some cases the mutex life can be less than the structure containing it.

Stepan,

I think Jonathan is right, so I'm going to drop the Fixes tag for this one, and pick up as well the original revision of your interrupt-cnt patch without the Fixes tag. Sorry for the noise.

Thank you,

William Breathitt Gray

maintainer Applied
#6 lore raw
In reply to Stepan Ionichev
Quoted 9 lines · Stepan Ionichev

ftm_quaddec_probe() calls mutex_init() but neither the cleanup action nor a remove callback issues a matching mutex_destroy(), 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.

[...]

Applied, thanks!

[1/1] counter: ftm-quaddec: use devm_mutex_init()

      commit: f981309937538ca7425fbf65fe4c339c00e50eca

Best regards,

Signature · 1 line
William Breathitt Gray <[email protected]>