[PATCH v5 2/3] iio: proximity: sx9324: keep the IRQ balanced across suspend and resume

From: Arnav Kapoor

Date: Sat Nov 14 2026 - 02:36:42 EST


sx9324_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. sx9324_resume() also
returns without enabling it on error.

Enable the interrupt again when suspend fails, and enable it as the
first step of resume, before anything can fail, so resume mirrors
suspend. Use disable_irq() rather than disable_irq_nosync(), and call
it before taking the mutex, which the threaded handlers also take, so
none of them is left to run once suspend has returned. The driver works
without an interrupt line, so skip these calls when client->irq is 0,
as sx_common already does.

Fixes: 4c18a890dff8 ("iio:proximity:sx9324: Add SX9324 support")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
drivers/iio/proximity/sx9324.c | 43 +++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
index 1c8ba28c030a..ed2caadc7747 100644
--- a/drivers/iio/proximity/sx9324.c
+++ b/drivers/iio/proximity/sx9324.c
@@ -1091,15 +1091,13 @@ static int sx9324_probe(struct i2c_client *client)
return sx_common_probe(client, &sx9324_chip_info, &sx9324_regmap_config);
}

-static int sx9324_suspend(struct device *dev)
+static int sx9324_sleep(struct sx_common_data *data)
{
- struct sx_common_data *data = iio_priv(dev_get_drvdata(dev));
unsigned int regval;
int ret;

- disable_irq_nosync(data->client->irq);
-
guard(mutex)(&data->mutex);
+
ret = regmap_read(data->regmap, SX9324_REG_GNRL_CTRL1, &regval);
if (ret < 0)
return ret;
@@ -1107,25 +1105,42 @@ static int sx9324_suspend(struct device *dev)
data->suspend_ctrl =
FIELD_GET(SX9324_REG_GNRL_CTRL1_PHEN_MASK, regval);

-
/* Disable all phases, send the device to sleep. */
return regmap_write(data->regmap, SX9324_REG_GNRL_CTRL1, 0);
}

+static int sx9324_suspend(struct device *dev)
+{
+ struct sx_common_data *data = iio_priv(dev_get_drvdata(dev));
+ int ret;
+
+ /*
+ * Before taking the mutex, as disable_irq() waits for the threaded
+ * handlers and they take it too.
+ */
+ if (data->client->irq)
+ disable_irq(data->client->irq);
+
+ ret = sx9324_sleep(data);
+ /* Resume isn't called if suspend fails. */
+ if (ret && data->client->irq)
+ enable_irq(data->client->irq);
+
+ return ret;
+}
+
static int sx9324_resume(struct device *dev)
{
struct sx_common_data *data = iio_priv(dev_get_drvdata(dev));

- scoped_guard(mutex, &data->mutex) {
- int ret = regmap_write(data->regmap, SX9324_REG_GNRL_CTRL1,
- data->suspend_ctrl |
- SX9324_REG_GNRL_CTRL1_PAUSECTRL);
- if (ret)
- return ret;
- }
+ if (data->client->irq)
+ enable_irq(data->client->irq);

- enable_irq(data->client->irq);
- return 0;
+ guard(mutex)(&data->mutex);
+
+ return regmap_write(data->regmap, SX9324_REG_GNRL_CTRL1,
+ data->suspend_ctrl |
+ SX9324_REG_GNRL_CTRL1_PAUSECTRL);
}

static DEFINE_SIMPLE_DEV_PM_OPS(sx9324_pm_ops, sx9324_suspend, sx9324_resume);
--
2.53.0