From ee4133b921a17b239ca617e9b0c16cad1277e9fd Mon Sep 17 00:00:00 2001 From: Joao Paulo Menezes Linaris Date: Tue, 12 May 2026 14:30:57 -0300 Subject: [PATCH 1/4] counter: intel-qep: Replace manual mutex logic with lock guards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use guard() for handling mutex lock instead of locking and unlocking mutex explicitly. This improves readability by eliminating the need for gotos and by clearly indicating mutex will be locked only when execution is in guard scope. Signed-off-by: Joao Paulo Menezes Linaris Co-developed-by: Guilherme Dias Signed-off-by: Guilherme Dias Reviewed-by: Ilpo Järvinen Link: https://lore.kernel.org/r/20260512173058.14858-1-jplinaris@usp.br Signed-off-by: William Breathitt Gray --- drivers/counter/intel-qep.c | 50 +++++++++++++------------------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c index c49c178056f4..9c6536f75afd 100644 --- a/drivers/counter/intel-qep.c +++ b/drivers/counter/intel-qep.c @@ -188,25 +188,21 @@ static int intel_qep_ceiling_write(struct counter_device *counter, struct counter_count *count, u64 max) { struct intel_qep *qep = counter_priv(counter); - int ret = 0; /* Intel QEP ceiling configuration only supports 32-bit values */ if (max != (u32)max) return -ERANGE; - mutex_lock(&qep->lock); - if (qep->enabled) { - ret = -EBUSY; - goto out; - } + guard(mutex)(&qep->lock); + + if (qep->enabled) + return -EBUSY; pm_runtime_get_sync(qep->dev); intel_qep_writel(qep, INTEL_QEPMAX, max); pm_runtime_put(qep->dev); -out: - mutex_unlock(&qep->lock); - return ret; + return 0; } static int intel_qep_enable_read(struct counter_device *counter, @@ -226,10 +222,11 @@ static int intel_qep_enable_write(struct counter_device *counter, u32 reg; bool changed; - mutex_lock(&qep->lock); + guard(mutex)(&qep->lock); + changed = val ^ qep->enabled; if (!changed) - goto out; + return 0; pm_runtime_get_sync(qep->dev); reg = intel_qep_readl(qep, INTEL_QEPCON); @@ -246,8 +243,6 @@ static int intel_qep_enable_write(struct counter_device *counter, pm_runtime_put(qep->dev); qep->enabled = val; -out: - mutex_unlock(&qep->lock); return 0; } @@ -279,7 +274,6 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter, struct intel_qep *qep = counter_priv(counter); u32 reg; bool enable; - int ret = 0; /* * Spike filter length is (MAX_COUNT + 2) clock periods. @@ -300,11 +294,10 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter, if (length > INTEL_QEPFLT_MAX_COUNT(length)) return -ERANGE; - mutex_lock(&qep->lock); - if (qep->enabled) { - ret = -EBUSY; - goto out; - } + guard(mutex)(&qep->lock); + + if (qep->enabled) + return -EBUSY; pm_runtime_get_sync(qep->dev); reg = intel_qep_readl(qep, INTEL_QEPCON); @@ -316,9 +309,7 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter, intel_qep_writel(qep, INTEL_QEPCON, reg); pm_runtime_put(qep->dev); -out: - mutex_unlock(&qep->lock); - return ret; + return 0; } static int intel_qep_preset_enable_read(struct counter_device *counter, @@ -342,13 +333,11 @@ static int intel_qep_preset_enable_write(struct counter_device *counter, { struct intel_qep *qep = counter_priv(counter); u32 reg; - int ret = 0; - mutex_lock(&qep->lock); - if (qep->enabled) { - ret = -EBUSY; - goto out; - } + guard(mutex)(&qep->lock); + + if (qep->enabled) + return -EBUSY; pm_runtime_get_sync(qep->dev); reg = intel_qep_readl(qep, INTEL_QEPCON); @@ -360,10 +349,7 @@ static int intel_qep_preset_enable_write(struct counter_device *counter, intel_qep_writel(qep, INTEL_QEPCON, reg); pm_runtime_put(qep->dev); -out: - mutex_unlock(&qep->lock); - - return ret; + return 0; } static struct counter_comp intel_qep_count_ext[] = { From b400c076fe4b63576fa22fbb59078b030000970c Mon Sep 17 00:00:00 2001 From: Stepan Ionichev Date: Sat, 23 May 2026 23:43:51 +0500 Subject: [PATCH 2/4] 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(), so the lock debug state is leaked on driver unbind. Switch to devm_mutex_init() so the mutex is torn down in the same devm scope it was set up in. Signed-off-by: Stepan Ionichev Reviewed-by: Joshua Crofts Link: https://lore.kernel.org/r/20260523184351.7567-1-sozdayvek@gmail.com Signed-off-by: William Breathitt Gray --- drivers/counter/ftm-quaddec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c index c47741292ae1..8455f16d62cb 100644 --- a/drivers/counter/ftm-quaddec.c +++ b/drivers/counter/ftm-quaddec.c @@ -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); From 4d9a902be374aea023f2193f729c26612e56b542 Mon Sep 17 00:00:00 2001 From: Stepan Ionichev Date: Sat, 23 May 2026 23:44:18 +0500 Subject: [PATCH 3/4] 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. Signed-off-by: Stepan Ionichev Reviewed-by: Joshua Crofts Link: https://lore.kernel.org/r/20260523184418.7586-1-sozdayvek@gmail.com Signed-off-by: William Breathitt Gray --- drivers/counter/interrupt-cnt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c index e6100b5fb082..cd475382ab6a 100644 --- a/drivers/counter/interrupt-cnt.c +++ b/drivers/counter/interrupt-cnt.c @@ -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) From ca815bb87064a8f68b00eaf8872ef0d4a33a5bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Wed, 20 May 2026 14:18:12 +0300 Subject: [PATCH 4/4] counter: intel-qep: Use devm_mutex_init() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit intel_qep_probe() calls mutex_init() but lacks the pairing mutex_destroy() calls. Convert to devm_mutex_init() which handles cleanup automatically. Signed-off-by: Ilpo Järvinen Reviewed-by: Joshua Crofts Reviewed-by: Stepan Ionichev Link: https://lore.kernel.org/r/20260520111813.3934-1-ilpo.jarvinen@linux.intel.com Signed-off-by: William Breathitt Gray --- drivers/counter/intel-qep.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c index 9c6536f75afd..3181da47e9d4 100644 --- a/drivers/counter/intel-qep.c +++ b/drivers/counter/intel-qep.c @@ -400,7 +400,9 @@ static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id) qep->dev = dev; qep->regs = regs; - mutex_init(&qep->lock); + ret = devm_mutex_init(dev, &qep->lock); + if (ret) + return ret; intel_qep_init(qep); pci_set_drvdata(pci, qep);