Skip to contentSkip to conversation

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

PATCH Superseded Stepan Ionichev 2 participants 3 messages May 20 – May 26

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 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 b64a8a407..0ec3a0c4b 100644
@@ -481,6 +481,11 @@ static const struct iio_chan_spec iadc_channels[] = {
 	},
 };
 
+static void iadc_disable_irq_wake(void *data)
+{
+	disable_irq_wake((unsigned 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 *)(unsigned 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 Thu, 21 May 2026 00:09:24 +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 7 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.

Looks mostly good - one trivial question inline.

Quoted 9 lines
---
 drivers/iio/adc/qcom-spmi-iadc.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/iio/adc/qcom-spmi-iadc.c +0 -0
index b64a8a407..0ec3a0c4b 100644

drivers/iio/adc/qcom-spmi-iadc.c static const struct iio_chan_spec iadc_channels[] = { · line 486

Quoted 6 lines
drivers/iio/adc/qcom-spmi-iadc.c +3 -0
@@ -481,6 +481,11 @@ static const struct iio_chan_spec iadc_channels[] = {
 	},
 };
 
+static void iadc_disable_irq_wake(void *data)
+{
+	disable_irq_wake((unsigned long)data);

Why not cast it to an int given that's what disable_irq_wake() takes

Quoted 11 lines
drivers/iio/adc/qcom-spmi-iadc.c +2 -2
+}
+
 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);

drivers/iio/adc/qcom-spmi-iadc.c static int iadc_probe(struct platform_device *pdev) · line 554

Quoted 10 lines
drivers/iio/adc/qcom-spmi-iadc.c +9 -1
-		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 *)(unsigned long)irq_eoc);

What is the unsigned long bit of this cast giving us? Just casting to void * should be enough I think.

Quoted 4 lines
drivers/iio/adc/qcom-spmi-iadc.c +1 -0
+		if (ret)
 			return ret;
 	} else {
 		ret = devm_device_init_wakeup(iadc->dev);
maintainer
#2 lore raw
Quoted 51 lines · On Fri, 22 May 2026 15:58:49 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 5 lines · On Thu, 21 May 2026 00:09:24 +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 7 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.

Looks mostly good - one trivial question inline.

Quoted 9 lines
---
 drivers/iio/adc/qcom-spmi-iadc.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/iio/adc/qcom-spmi-iadc.c +0 -0
index b64a8a407..0ec3a0c4b 100644

drivers/iio/adc/qcom-spmi-iadc.c static const struct iio_chan_spec iadc_channels[] = { · line 486

Quoted 6 lines
drivers/iio/adc/qcom-spmi-iadc.c +3 -0
@@ -481,6 +481,11 @@ static const struct iio_chan_spec iadc_channels[] = {
 	},
 };
 
+static void iadc_disable_irq_wake(void *data)
+{
+	disable_irq_wake((unsigned long)data);  

Why not cast it to an int given that's what disable_irq_wake() takes

Quoted 16 lines
drivers/iio/adc/qcom-spmi-iadc.c +6 -3
+}
+
 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);
Quoted 8 lines

drivers/iio/adc/qcom-spmi-iadc.c static int iadc_probe(struct platform_device *pdev) · line 554

Quoted 5 lines
drivers/iio/adc/qcom-spmi-iadc.c +5 -0
+		if (ret)
+			return ret;
+
+		ret = devm_add_action_or_reset(dev, iadc_disable_irq_wake,
+					       (void *)(unsigned long)irq_eoc);  

What is the unsigned long bit of this cast giving us? Just casting to void * should be enough I think.

The answer to this was size mismatch - so I was completely wrong ;(

So as I just replied to v2 this was correct, but could do with a Fixes tag.

Thanks

Jonathan

Quoted 8 lines
Quoted 6 lines
drivers/iio/adc/qcom-spmi-iadc.c +1 -0
+		if (ret)
 			return ret;
 	} else {
 		ret = devm_device_init_wakeup(iadc->dev);