Skip to contentSkip to conversation

iio: adc: qcom-spmi-iadc: balance enable_irq_wake() on driver unbind

PATCH In review Stepan Ionichev 3 participants 4 messages May 29 – Jul 6

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 iio: adc: qcom-spmi-iadc: balance enable_irq_wake() on driver unbind

iadc_probe() calls enable_irq_wake() after a successful devm_request_irq(), but the driver has no remove callback or matching disable_irq_wake(), so the wake reference count on the IRQ is leaked on module unload or driver unbind.

Check the IRQ request error first, then register a devm action that calls disable_irq_wake() so the wake reference is released in the same scope as the enable. While here, drop the inverted "if (!ret) ... else return ret" in favour of the standard "if (ret) return ret;" pattern.

Fixes ce0694841ea6 ("iio: iadc: Qualcomm SPMI PMIC current ADC driver")

---
v3:
- Add Fixes tag (Jonathan)

v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

 drivers/iio/adc/qcom-spmi-iadc.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/iio/adc/qcom-spmi-iadc.c +15 -3
index b64a8a407168..88f6be2108e7 100644
@@ -481,6 +481,11 @@ static const struct iio_chan_spec iadc_channels[] = {
 	},
 };
 
+static void iadc_disable_irq_wake(void *data)
+{
+	disable_irq_wake((long)data);
+}
+
 static int iadc_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
@@ -538,9 +543,16 @@ static int iadc_probe(struct platform_device *pdev)
 	if (!iadc->poll_eoc) {
 		ret = devm_request_irq(dev, irq_eoc, iadc_isr, 0,
 					"spmi-iadc", iadc);
-		if (!ret)
-			enable_irq_wake(irq_eoc);
-		else
+		if (ret)
+			return ret;
+
+		ret = enable_irq_wake(irq_eoc);
+		if (ret)
+			return ret;
+
+		ret = devm_add_action_or_reset(dev, iadc_disable_irq_wake,
+					       (void *)(long)irq_eoc);
+		if (ret)
 			return ret;
 	} else {
 		ret = devm_device_init_wakeup(iadc->dev);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 5 lines · On Fri, 29 May 2026 14:56:48 +0500 Stepan Ionichev <[email protected]> wrote:

iadc_probe() calls enable_irq_wake() after a successful devm_request_irq(), but the driver has no remove callback or matching disable_irq_wake(), so the wake reference count on the IRQ is leaked on module unload or driver unbind.

Quoted 8 lines

Check the IRQ request error first, then register a devm action that calls disable_irq_wake() so the wake reference is released in the same scope as the enable. While here, drop the inverted "if (!ret) ... else return ret" in favour of the standard "if (ret) return ret;" pattern.

Fixes ce0694841ea6 ("iio: iadc: Qualcomm SPMI PMIC current ADC driver")

+CC Bjorn and Konrad as we don't seem to have a more specific maintainer for this driver.

Seems low risk, but nice to run it past them.

Thanks,

Jonathan

Quoted 46 lines

---
v3:
- Add Fixes tag (Jonathan)

v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

 drivers/iio/adc/qcom-spmi-iadc.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/iio/adc/qcom-spmi-iadc.c +15 -3
index b64a8a407168..88f6be2108e7 100644
@@ -481,6 +481,11 @@ static const struct iio_chan_spec iadc_channels[] = {
 	},
 };
 
+static void iadc_disable_irq_wake(void *data)
+{
+	disable_irq_wake((long)data);
+}
+
 static int iadc_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
@@ -538,9 +543,16 @@ static int iadc_probe(struct platform_device *pdev)
 	if (!iadc->poll_eoc) {
 		ret = devm_request_irq(dev, irq_eoc, iadc_isr, 0,
 					"spmi-iadc", iadc);
-		if (!ret)
-			enable_irq_wake(irq_eoc);
-		else
+		if (ret)
+			return ret;
+
+		ret = enable_irq_wake(irq_eoc);
+		if (ret)
+			return ret;
+
+		ret = devm_add_action_or_reset(dev, iadc_disable_irq_wake,
+					       (void *)(long)irq_eoc);
+		if (ret)
 			return ret;
 	} else {
 		ret = devm_device_init_wakeup(iadc->dev);
Reviewed-by
#2 lore raw
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Fri, 29 May 2026 14:56:48 +0500 Stepan Ionichev <[email protected]> wrote:

iadc_probe() calls enable_irq_wake() after a successful devm_request_irq(), but the driver has no remove callback or matching disable_irq_wake(), so the wake reference count on the IRQ is leaked on module unload or driver unbind.

Check the IRQ request error first, then register a devm action that calls disable_irq_wake() so the wake reference is released in the same scope as the enable. While here, drop the inverted "if (!ret) ... else return ret" in favour of the standard "if (ret) return ret;" pattern.

Quoted 7 lines
Quoted 2 lines
Fixes ce0694841ea6 ("iio: iadc: Qualcomm SPMI PMIC current ADC driver")

+CC Bjorn and Konrad as we don't seem to have a more specific maintainer for this driver.

Seems low risk, but nice to run it past them.

The robot pointed out to me that this makes probe fail if the irqchip isn't wakeup-capable, but it seems like that's never the case for the one that will be used (i.e. the QC SPMI bus arbiter)

so:

Konrad

maintainer
#3 lore raw
Quoted 23 lines · On Mon, 6 Jul 2026 13:25:48 +0200 Konrad Dybcio…
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Fri, 29 May 2026 14:56:48 +0500 Stepan Ionichev <[email protected]> wrote:

iadc_probe() calls enable_irq_wake() after a successful devm_request_irq(), but the driver has no remove callback or matching disable_irq_wake(), so the wake reference count on the IRQ is leaked on module unload or driver unbind.

Check the IRQ request error first, then register a devm action that calls disable_irq_wake() so the wake reference is released in the same scope as the enable. While here, drop the inverted "if (!ret) ... else return ret" in favour of the standard "if (ret) return ret;" pattern.

Quoted 7 lines
Quoted 2 lines
Fixes ce0694841ea6 ("iio: iadc: Qualcomm SPMI PMIC current ADC driver")

+CC Bjorn and Konrad as we don't seem to have a more specific maintainer for this driver.

Seems low risk, but nice to run it past them.

Quoted 8 lines

The robot pointed out to me that this makes probe fail if the irqchip isn't wakeup-capable, but it seems like that's never the case for the one that will be used (i.e. the QC SPMI bus arbiter)

so:

I'm clearly going crazy. Seems I picked up an earlier version and failed to track that correctly. It's already upstream and from a quick eyeball is the same as this patch (I think I must have picked up v1 after v2 discussion showing that was right option).

Thanks anyway and at least this record will exist of that wakeup-capable thing.

Jonathan

Quoted 1 line

Konrad