Skip to contentSkip to conversation

iio: proximity: sx9360: keep the IRQ balanced across suspend and resume

PATCH Superseded Arnav Kapoor 2 participants 2 messages Oct 26 IIO

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: proximity: sx9360: keep the IRQ balanced across suspend and resume

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")

---
I'm sending the same fix for sx9310, sx9324 and sx9360 as separate patches, as the Fixes tags differ.

Compile-tested only (W=1); I don't have SX9360 hardware and haven't reproduced a failing suspend.

 drivers/iio/proximity/sx9360.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/iio/proximity/sx9360.c +20 -13
index ed83d809ecf5..85b83d86a433 100644
@@ -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);

base-commit: 2ef6f5c4ee56e90c237c5f7687f09e635f7d30a9

Signature · 1 line
2.53.0
#1 lore raw
Quoted 7 lines · On Mon, 26 Oct 2026 15:34:47 +0530 Arnav Kapoor <[email protected]> wrote:

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.

Quoted 8 lines

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")

---
I'm sending the same fix for sx9310, sx9324 and sx9360 as separate patches, as the Fixes tags differ.

Shame you didn't send the patches as a series with a cover letter given it's the same logical change and that it concerns the sx93xx series.

Signature · 2 lines
Kind regards,
Joshua Crofts