From: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Michal Simek" <michal.simek@amd.com>,
"Sai Krishna Potthuri" <sai.krishna.potthuri@amd.com>,
"Prasanna Kumar T S M" <ptsm@linux.microsoft.com>,
linux-kernel@vger.kernel.org, git@amd.com,
amitrkcian2002@gmail.com,
"Amit Kumar Mahapatra" <amit.kumar-mahapatra@amd.com>
Subject: [PATCH v2 1/3] iio: adc: versal-sysmon: fix race in interrupt teardown
Date: Mon, 30 Nov 2026 15:49:35 +0530 [thread overview]
Message-ID: <20261130101937.1022383-2-amit.kumar-mahapatra@amd.com> (raw)
In-Reply-To: <20261130101937.1022383-1-amit.kumar-mahapatra@amd.com>
sysmon_disable_interrupts() masks all interrupts, then clears masked_temp
under irq_lock and cancels the unmask worker. A worker that runs between
the mask write and the locked section still sees the old masked_temp and
can re-enable an alarm through IER. If that alarm fires, the handler
queues the worker again after cancel_delayed_work_sync() has returned.
On unbind this action runs before devm releases the IRQ, so the queued
work can run after the devm-allocated iio_dev that embeds it has been
freed.
Mask all interrupts and clear masked_temp in the same irq_lock section,
and only then cancel the worker. A worker that runs afterwards has
nothing to unmask, and a handler finds every source masked and returns
IRQ_NONE without queueing work. Make sysmon_unmask_temp() return early
when nothing is masked, so that the worker does not touch IER once
teardown has cleared masked_temp.
Fixes: c7f7eb10638f ("iio: adc: versal-sysmon: add threshold event support")
Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
---
Changes in v2:
- Drop disable_irq() and the stored IRQ number. Mask all interrupts and
clear masked_temp under irq_lock before cancelling the worker (Jonathan)
- Return early from sysmon_unmask_temp() when nothing is masked (Jonathan)
- Drop Prasanna's Reviewed-by, as the fix has changed
drivers/iio/adc/versal-sysmon-core.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/adc/versal-sysmon-core.c b/drivers/iio/adc/versal-sysmon-core.c
index 1b55d343982e..a7ff65075d7d 100644
--- a/drivers/iio/adc/versal-sysmon-core.c
+++ b/drivers/iio/adc/versal-sysmon-core.c
@@ -712,6 +712,9 @@ static void sysmon_unmask_temp(struct sysmon *sysmon, unsigned int isr)
unsigned int status;
u32 ier;
+ if (!sysmon->masked_temp)
+ return;
+
status = isr & SYSMON_TEMP_INTR_MASK;
ier = ~status & sysmon->masked_temp;
@@ -781,10 +784,10 @@ static void sysmon_disable_interrupts(void *data)
{
struct sysmon *sysmon = data;
- regmap_write(sysmon->regmap, SYSMON_IDR, SYSMON_INTR_ALL_MASK);
-
- scoped_guard(spinlock_irq, &sysmon->irq_lock)
+ scoped_guard(spinlock_irq, &sysmon->irq_lock) {
+ regmap_write(sysmon->regmap, SYSMON_IDR, SYSMON_INTR_ALL_MASK);
sysmon->masked_temp = 0;
+ }
cancel_delayed_work_sync(&sysmon->sysmon_unmask_work);
}
--
2.44.4
next prev parent reply other threads:[~2026-11-30 10:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 10:19 [PATCH v2 0/3] iio: adc: versal-sysmon: Fix interrupt teardown and hysteresis, update maintainers Amit Kumar Mahapatra
2026-11-30 10:19 ` Amit Kumar Mahapatra [this message]
2026-11-30 15:00 ` [PATCH v2 1/3] iio: adc: versal-sysmon: fix race in interrupt teardown Arnav Kapoor
2026-11-30 10:19 ` [PATCH v2 2/3] iio: adc: versal-sysmon: validate temperature hysteresis Amit Kumar Mahapatra
2026-11-30 15:00 ` Arnav Kapoor
2026-11-30 10:19 ` [PATCH v2 3/3] MAINTAINERS: update Versal SysMon maintainers Amit Kumar Mahapatra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130101937.1022383-2-amit.kumar-mahapatra@amd.com \
--to=amit.kumar-mahapatra@amd.com \
--cc=amitrkcian2002@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=git@amd.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=nuno.sa@analog.com \
--cc=ptsm@linux.microsoft.com \
--cc=sai.krishna.potthuri@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®