[PATCH v2 3/3] iio: proximity: sx9360: keep the IRQ balanced across suspend and resume

From: Arnav Kapoor

Date: Mon Oct 26 2026 - 07:54:18 EST


sx9360_suspend() disables the interrupt first and returns with it still
disabled if a register access fails. Resume isn't called after a failed
suspend, so the interrupt is never enabled again. sx9360_resume() also
returns without enabling it on error. Without an interrupt line,
client->irq is 0 and both callbacks act on IRQ 0, which the driver
doesn't own.

Disable the interrupt only once the device is asleep, always enable it
in resume, and skip both when there is no interrupt.

Fixes: 1cdb4c47f7f5 ("iio:proximity:sx9360: Add sx9360 support")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
drivers/iio/proximity/sx9360.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/proximity/sx9360.c b/drivers/iio/proximity/sx9360.c
index ed83d809ecf5..85b83d86a433 100644
--- a/drivers/iio/proximity/sx9360.c
+++ b/drivers/iio/proximity/sx9360.c
@@ -797,8 +797,6 @@ static int sx9360_suspend(struct device *dev)
unsigned int regval;
int ret;

- disable_irq_nosync(data->client->irq);
-
guard(mutex)(&data->mutex);
ret = regmap_read(data->regmap, SX9360_REG_GNRL_CTRL0, &regval);
if (ret < 0)
@@ -809,23 +807,32 @@ static int sx9360_suspend(struct device *dev)


/* Disable all phases, send the device to sleep. */
- return regmap_write(data->regmap, SX9360_REG_GNRL_CTRL0, 0);
+ ret = regmap_write(data->regmap, SX9360_REG_GNRL_CTRL0, 0);
+ if (ret)
+ return ret;
+
+ /* Only once nothing can fail, as resume isn't called on failure. */
+ if (data->client->irq)
+ disable_irq_nosync(data->client->irq);
+
+ return 0;
}

static int sx9360_resume(struct device *dev)
{
struct sx_common_data *data = iio_priv(dev_get_drvdata(dev));
+ int ret;

- scoped_guard(mutex, &data->mutex) {
- int ret = regmap_update_bits(data->regmap,
- SX9360_REG_GNRL_CTRL0,
- SX9360_REG_GNRL_CTRL0_PHEN_MASK,
- data->suspend_ctrl);
- if (ret)
- return ret;
- }
- enable_irq(data->client->irq);
- return 0;
+ scoped_guard(mutex, &data->mutex)
+ ret = regmap_update_bits(data->regmap, SX9360_REG_GNRL_CTRL0,
+ SX9360_REG_GNRL_CTRL0_PHEN_MASK,
+ data->suspend_ctrl);
+
+ /* Balance the suspend even if the device couldn't be woken up. */
+ if (data->client->irq)
+ enable_irq(data->client->irq);
+
+ return ret;
}

static DEFINE_SIMPLE_DEV_PM_OPS(sx9360_pm_ops, sx9360_suspend, sx9360_resume);
--
2.53.0