Skip to contentSkip to conversation

counter: interrupt-cnt: use devm_mutex_init()

PATCH Applied Stepan Ionichev 3 participants 4 messages May 23 – May 31

Subsystems (3)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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, so the lock debug state is leaked.

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

---
 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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Stepan Ionichev

interrupt_cnt_probe() calls mutex_init() but neither this driver nor the counter core issues a matching mutex_destroy() on unbind, so the lock debug state is leaked.

A little bit of a misconception, however unless you compile the kernel with CONFIG_DEBUG_MUTEXES enabled, mutex_destroy() will translate into a nop, so there won't be any leaks. Nevertheless, the devm_ counterpart makes debugging easier, therefore

Signature · 3 lines
Kind regards

CJD
#2 lore raw
In reply to Stepan Ionichev
Quoted 8 lines · Stepan Ionichev

interrupt_cnt_probe() calls mutex_init() but neither this driver nor the counter core issues a matching mutex_destroy() on unbind, so the lock debug state is leaked.

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

This sounds like a bug fix (albeit applicable only under CONFIG_DEBUG_MUTEXES) so we should have a Fixes tag here, correct?

If this issue applies to counter-core and counter-chrdev, would you submit patches for them as well?

William Breathitt Gray

maintainer Applied
#3 lore raw
In reply to Stepan Ionichev
Quoted 8 lines · Stepan Ionichev

interrupt_cnt_probe() calls mutex_init() but neither this driver nor the counter core issues a matching mutex_destroy() on unbind, so the lock debug state is leaked.

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: interrupt-cnt: use devm_mutex_init()

      commit: 4d9a902be374aea023f2193f729c26612e56b542

Best regards,

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