* [PATCH v2 1/3] iio: adc: versal-sysmon: fix race in interrupt teardown
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
2026-11-30 10:19 ` [PATCH v2 2/3] iio: adc: versal-sysmon: validate temperature hysteresis Amit Kumar Mahapatra
2026-11-30 10:19 ` [PATCH v2 3/3] MAINTAINERS: update Versal SysMon maintainers Amit Kumar Mahapatra
2 siblings, 0 replies; 4+ messages in thread
From: Amit Kumar Mahapatra @ 2026-11-30 10:19 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá,
Andy Shevchenko, Michal Simek, Sai Krishna Potthuri,
Prasanna Kumar T S M, linux-kernel, git, amitrkcian2002,
Amit Kumar Mahapatra
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
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 2/3] iio: adc: versal-sysmon: validate temperature hysteresis
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 ` [PATCH v2 1/3] iio: adc: versal-sysmon: fix race in interrupt teardown Amit Kumar Mahapatra
@ 2026-11-30 10:19 ` Amit Kumar Mahapatra
2026-11-30 10:19 ` [PATCH v2 3/3] MAINTAINERS: update Versal SysMon maintainers Amit Kumar Mahapatra
2 siblings, 0 replies; 4+ messages in thread
From: Amit Kumar Mahapatra @ 2026-11-30 10:19 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá,
Andy Shevchenko, Michal Simek, Sai Krishna Potthuri,
Prasanna Kumar T S M, linux-kernel, git, amitrkcian2002,
Amit Kumar Mahapatra
The hysteresis written through sysfs is only checked for being negative.
A large value makes upper_mc - hysteresis in sysmon_update_temp_lower()
overflow before it is clamped. Reject values above the full Q8.7 span of
511992 millicelsius, and name the Q8.7 temperature limits so that the
span and the existing range checks share one definition.
The cached hysteresis is seeded at probe from the threshold registers
without checking that the lower threshold is not above the upper one.
These registers are not described in DT: at probe they hold either their
reset values or whatever the platform firmware programmed from the
design configuration. Failing the probe would take away every voltage
and temperature reading over a comparator setting the driver does not
own, so treat an inverted pair as zero hysteresis, as negative values
are rejected on the write path. The next threshold write then restores
lower = upper - hysteresis.
Fixes: c7f7eb10638f ("iio: adc: versal-sysmon: add threshold event support")
Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
---
Changes in v2:
- Explain in the commit message where the probe-time thresholds come
from, and why they are not rejected at probe (Andy)
drivers/iio/adc/versal-sysmon-core.c | 10 +++++-----
drivers/iio/adc/versal-sysmon.h | 4 ++++
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/adc/versal-sysmon-core.c b/drivers/iio/adc/versal-sysmon-core.c
index a7ff65075d7d..2bbc6808132c 100644
--- a/drivers/iio/adc/versal-sysmon-core.c
+++ b/drivers/iio/adc/versal-sysmon-core.c
@@ -352,7 +352,8 @@ static int sysmon_update_temp_lower(struct sysmon *sysmon)
return ret;
sysmon_q8p7_to_millicelsius(upper_reg, &upper_mc);
- lower_mc = clamp(upper_mc - sysmon->temp_hysteresis, -256000, 255992);
+ lower_mc = clamp(upper_mc - sysmon->temp_hysteresis,
+ SYSMON_TEMP_MIN_MC, SYSMON_TEMP_MAX_MC);
sysmon_millicelsius_to_q8p7(&raw_val, lower_mc);
return regmap_write(sysmon->regmap, SYSMON_TEMP_TH_LOW, raw_val);
@@ -429,8 +430,7 @@ static int sysmon_write_event_value(struct iio_dev *indio_dev,
case IIO_TEMP:
switch (info) {
case IIO_EV_INFO_VALUE:
- /* Q8.7 signed range: -256000 to +255992 mC */
- if (val < -256000 || val > 255992)
+ if (val < SYSMON_TEMP_MIN_MC || val > SYSMON_TEMP_MAX_MC)
return -EINVAL;
sysmon_millicelsius_to_q8p7(&raw_val, val);
@@ -443,7 +443,7 @@ static int sysmon_write_event_value(struct iio_dev *indio_dev,
return sysmon_update_temp_lower(sysmon);
case IIO_EV_INFO_HYSTERESIS:
- if (val < 0)
+ if (val < 0 || val > SYSMON_TEMP_MAX_MC - SYSMON_TEMP_MIN_MC)
return -EINVAL;
sysmon->temp_hysteresis = val;
@@ -838,7 +838,7 @@ static int sysmon_init_hysteresis(struct sysmon *sysmon, int *hysteresis)
sysmon_q8p7_to_millicelsius(upper_reg, &upper_mc);
sysmon_q8p7_to_millicelsius(lower_reg, &lower_mc);
- *hysteresis = upper_mc - lower_mc;
+ *hysteresis = max(upper_mc - lower_mc, 0);
return 0;
}
diff --git a/drivers/iio/adc/versal-sysmon.h b/drivers/iio/adc/versal-sysmon.h
index bb9a75bf71c0..930b7e7d21ce 100644
--- a/drivers/iio/adc/versal-sysmon.h
+++ b/drivers/iio/adc/versal-sysmon.h
@@ -75,6 +75,10 @@ struct regmap;
#define SYSMON_FRACTIONAL_SHIFT 7U
#define SYSMON_SUPPLY_MANTISSA_BITS 16
+/* Q8.7 signed temperature range in millicelsius */
+#define SYSMON_TEMP_MIN_MC -256000
+#define SYSMON_TEMP_MAX_MC 255992
+
/* Bits per alarm register */
#define SYSMON_ALARM_BITS_PER_REG 32
--
2.44.4
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 3/3] MAINTAINERS: update Versal SysMon maintainers
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 ` [PATCH v2 1/3] iio: adc: versal-sysmon: fix race in interrupt teardown Amit Kumar Mahapatra
2026-11-30 10:19 ` [PATCH v2 2/3] iio: adc: versal-sysmon: validate temperature hysteresis Amit Kumar Mahapatra
@ 2026-11-30 10:19 ` Amit Kumar Mahapatra
2 siblings, 0 replies; 4+ messages in thread
From: Amit Kumar Mahapatra @ 2026-11-30 10:19 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, David Lechner, Nuno Sá,
Andy Shevchenko, Michal Simek, Sai Krishna Potthuri,
Prasanna Kumar T S M, linux-kernel, git, amitrkcian2002,
Amit Kumar Mahapatra
Replace Salih Erim with myself as a maintainer of the Versal SysMon
driver.
Acked-by: Michal Simek <michal.simek@amd.com>
Acked-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
---
Changes in v2:
- Collect Acked-by from Michal and Sai
MAINTAINERS | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 02015eaec312..a8f8d936fa12 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30800,8 +30800,8 @@ F: drivers/edac/versalnet_edac.c
F: include/linux/cdx/edac_cdx_pcol.h
XILINX VERSAL SYSMON DRIVER
-M: Salih Erim <salih.erim@amd.com>
M: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
+M: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
L: linux-iio@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml
--
2.44.4
^ permalink raw reply [flat|nested] 4+ messages in thread