Skip to contentSkip to conversation

iio: Use IRQF_NO_AUTOEN

PATCH In review Jonathan Cameron 6 participants 27 messages Apr 2, 2021 – Apr 6, 2021

Subsystems (8)
lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover iio: Use IRQF_NO_AUTOEN

From: Jonathan Cameron <[email protected]>

This series is dependant on
cbe16f35bee68 ("genirq: Add IRQF_NO_AUTOEN for request_irq/nmi()") which is available in an immutable tag in the tip tree.
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/tag/?h=irq-no-autoen-2021-03-25
which I'll merge in to the IIO tree if we need it before it's available upstream.

That patch introduces a new IRQF_NO_AUTOEN flag for irq requests to avoid the current dance where we either mark an irq as not to be autoenabled before we know if we can actually request it succesfully, or (as IIO drivers seem to have gone with) we disable the interrupt just after requesting it. In short the flag stops the interrupt being autoenabled in the first place.

So this series applies this magic to IIO :)

Note these are all just compile tested and some of them aren't entirely trivial because of other aspects of the irq flag handling.

Jonathan Cameron (7):
iio:adc:ad7766: Use new IRQF_NO_AUTOEN to reduce boilerplate iio:adc:exynos-adc: Use new IRQF_NO_AUTOEN flag rather than separate
irq_disable()
iio:adc:nau7802: Use IRQF_NO_AUTOEN instead of request then disable iio:adc:sun4i-gpadc: Use new IRQF_NO_AUTOEN flag instead of request
then disable
iio:chemical:scd30: Use IRQF_NO_AUTOEN to avoid irq request then
disable
iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and
disable

 drivers/iio/adc/ad7766.c          | 15 +++++++--------
 drivers/iio/adc/ad_sigma_delta.c  |  7 ++-----
 drivers/iio/adc/exynos_adc.c      |  4 ++--
 drivers/iio/adc/nau7802.c         |  6 +++---
 drivers/iio/adc/sun4i-gpadc-iio.c |  4 ++--
 drivers/iio/chemical/scd30_core.c | 16 ++++++++--------
 drivers/iio/imu/adis16460.c       |  4 ++--
 drivers/iio/imu/adis16475.c       |  5 +++--
 drivers/iio/imu/adis_trigger.c    | 11 ++++++-----
 9 files changed, 35 insertions(+), 37 deletions(-)
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 1/7 iio:adc:ad7766: Use new IRQF_NO_AUTOEN to reduce boilerplate

From: Jonathan Cameron <[email protected]>

As iio_poll_trigger() is safe against spurious interrupts when the trigger is not enabled, this is not a fix despite looking like a race. It is nice to simplify the code however so the interrupt is never enabled in the first place.

Cc Lars-Peter Clausen <[email protected]>
---
 drivers/iio/adc/ad7766.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7766.c +7 -8
index 829a3426f235..1e41759f3ee5 100644
@@ -255,18 +255,17 @@ static int ad7766_probe(struct spi_device *spi)
 		ad7766->trig->ops = &ad7766_trigger_ops;
 		iio_trigger_set_drvdata(ad7766->trig, ad7766);
 
-		ret = devm_request_irq(&spi->dev, spi->irq, ad7766_irq,
-			IRQF_TRIGGER_FALLING, dev_name(&spi->dev),
-			ad7766->trig);
-		if (ret < 0)
-			return ret;
-
 		/*
 		 * The device generates interrupts as long as it is powered up.
 		 * Some platforms might not allow the option to power it down so
-		 * disable the interrupt to avoid extra load on the system
+		 * don't enable the interrupt to avoid extra load on the system
 		 */
-		disable_irq(spi->irq);
+		ret = devm_request_irq(&spi->dev, spi->irq, ad7766_irq,
+				       IRQF_TRIGGER_FALLING | IRQF_NO_AUTOEN,
+				       dev_name(&spi->dev),
+				       ad7766->trig);
+		if (ret < 0)
+			return ret;
 
 		ret = devm_iio_trigger_register(&spi->dev, ad7766->trig);
 		if (ret)
Signature · 1 line
2.31.1
Reviewed-by on v1 1/7
#2 lore raw

RE: [PATCH 1/7] iio:adc:ad7766: Use new IRQF_NO_AUTOEN to reduce boilerplate

Quoted 13 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: [PATCH 1/7] iio:adc:ad7766: Use new IRQF_NO_AUTOEN to reduce boilerplate

From: Jonathan Cameron <[email protected]>

Quoted 8 lines

As iio_poll_trigger() is safe against spurious interrupts when the trigger is not enabled, this is not a fix despite looking like a race. It is nice to simplify the code however so the interrupt is never enabled in the first place.

Cc Lars-Peter Clausen <[email protected]>

---

BTW, +Cc Tiantao as Tao might be moving drivers to use IRQF_NO_AUTOEN.

Quoted 35 lines
 drivers/iio/adc/ad7766.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7766.c +7 -9
index 829a3426f235..1e41759f3ee5 100644
@@ -255,18 +255,17 @@ static int ad7766_probe(struct spi_device *spi)
 		ad7766->trig->ops = &ad7766_trigger_ops;
 		iio_trigger_set_drvdata(ad7766->trig, ad7766);
 
-		ret = devm_request_irq(&spi->dev, spi->irq, ad7766_irq,
-			IRQF_TRIGGER_FALLING, dev_name(&spi->dev),
-			ad7766->trig);
-		if (ret < 0)
-			return ret;
-
 		/*
 		 * The device generates interrupts as long as it is powered up.
 		 * Some platforms might not allow the option to power it down so
-		 * disable the interrupt to avoid extra load on the system
+		 * don't enable the interrupt to avoid extra load on the system
 		 */
-		disable_irq(spi->irq);
+		ret = devm_request_irq(&spi->dev, spi->irq, ad7766_irq,
+				       IRQF_TRIGGER_FALLING | IRQF_NO_AUTOEN,
+				       dev_name(&spi->dev),
+				       ad7766->trig);
+		if (ret < 0)
+			return ret;
 
 		ret = devm_iio_trigger_register(&spi->dev, ad7766->trig);
 		if (ret)
--

2.31.1

author maintainer
#3 lore raw

Re: [PATCH 1/7] iio:adc:ad7766: Use new IRQF_NO_AUTOEN to reduce boilerplate

Quoted 16 lines · On Fri, 2 Apr 2021 20:10:38 +0000 "Song Bao Hua (Barry Song)"…
Quoted 16 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: [PATCH 1/7] iio:adc:ad7766: Use new IRQF_NO_AUTOEN to reduce boilerplate

From: Jonathan Cameron <[email protected]>

As iio_poll_trigger() is safe against spurious interrupts when the trigger is not enabled, this is not a fix despite looking like a race. It is nice to simplify the code however so the interrupt is never enabled in the first place.

Quoted 5 lines
Quoted 3 lines
Cc Lars-Peter Clausen <[email protected]>

---

Applied to the togreg branch of iio.git and pushed out as testing to let the autobuilders see if they can find anything we missed.

Thanks,

Jonathan

Quoted 41 lines

BTW, +Cc Tiantao as Tao might be moving drivers to use IRQF_NO_AUTOEN.

Quoted 35 lines
 drivers/iio/adc/ad7766.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7766.c +7 -9
index 829a3426f235..1e41759f3ee5 100644
@@ -255,18 +255,17 @@ static int ad7766_probe(struct spi_device *spi)
 		ad7766->trig->ops = &ad7766_trigger_ops;
 		iio_trigger_set_drvdata(ad7766->trig, ad7766);
 
-		ret = devm_request_irq(&spi->dev, spi->irq, ad7766_irq,
-			IRQF_TRIGGER_FALLING, dev_name(&spi->dev),
-			ad7766->trig);
-		if (ret < 0)
-			return ret;
-
 		/*
 		 * The device generates interrupts as long as it is powered up.
 		 * Some platforms might not allow the option to power it down so
-		 * disable the interrupt to avoid extra load on the system
+		 * don't enable the interrupt to avoid extra load on the system
 		 */
-		disable_irq(spi->irq);
+		ret = devm_request_irq(&spi->dev, spi->irq, ad7766_irq,
+				       IRQF_TRIGGER_FALLING | IRQF_NO_AUTOEN,
+				       dev_name(&spi->dev),
+				       ad7766->trig);
+		if (ret < 0)
+			return ret;
 
 		ret = devm_iio_trigger_register(&spi->dev, ad7766->trig);
 		if (ret)
--

2.31.1

author maintainer
#4 lore raw

PATCH 2/7 iio:adc:exynos-adc: Use new IRQF_NO_AUTOEN flag rather than separate irq_disable()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Disabling an irq before the driver has actually atempted to request it may work, but is definitely not as clean as just requesting it as normal but with the auto enable disabled.

Cc Krzysztof Kozlowski <[email protected]>
---
 drivers/iio/adc/exynos_adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/exynos_adc.c +2 -2
index 784c10deeb1a..8c98d8c9ab1f 100644
@@ -778,9 +778,9 @@ static int exynos_adc_ts_init(struct exynos_adc *info)
 		return ret;
 	}
 
-	disable_irq(info->tsirq);
 	ret = request_threaded_irq(info->tsirq, NULL, exynos_ts_isr,
-				   IRQF_ONESHOT, "touchscreen", info);
+				   IRQF_ONESHOT | IRQF_NO_AUTOEN,
+				   "touchscreen", info);
 	if (ret)
 		input_unregister_device(info->input);
 
Signature · 1 line
2.31.1
Reviewed-by on v1 2/7
#5 lore raw

RE: [PATCH 2/7] iio:adc:exynos-adc: Use new IRQF_NO_AUTOEN flag rather than separate irq_disable()

Quoted 17 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Krzysztof Kozlowski <[email protected]>
Subject: [PATCH 2/7] iio:adc:exynos-adc: Use new IRQF_NO_AUTOEN flag rather than separate irq_disable()

From: Jonathan Cameron <[email protected]>

Disabling an irq before the driver has actually atempted to request it may work, but is definitely not as clean as just requesting it as normal but with the auto enable disabled.

Quoted 6 lines
Cc Krzysztof Kozlowski <[email protected]>
---
 drivers/iio/adc/exynos_adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 18 lines
drivers/iio/adc/exynos_adc.c +2 -3
index 784c10deeb1a..8c98d8c9ab1f 100644
@@ -778,9 +778,9 @@ static int exynos_adc_ts_init(struct exynos_adc *info)
 		return ret;
 	}
 
-	disable_irq(info->tsirq);
 	ret = request_threaded_irq(info->tsirq, NULL, exynos_ts_isr,
-				   IRQF_ONESHOT, "touchscreen", info);
+				   IRQF_ONESHOT | IRQF_NO_AUTOEN,
+				   "touchscreen", info);
 	if (ret)
 		input_unregister_device(info->input);
 
--

2.31.1

Reviewed-by on v1 2/7
#6 lore raw

Re: [PATCH 2/7] iio:adc:exynos-adc: Use new IRQF_NO_AUTOEN flag rather than separate irq_disable()

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Disabling an irq before the driver has actually atempted to request it may work, but is definitely not as clean as just requesting it as normal but with the auto enable disabled.

Cc Krzysztof Kozlowski <[email protected]>

Best regards,
Krzysztof

author maintainer
#7 lore raw

Re: [PATCH 2/7] iio:adc:exynos-adc: Use new IRQF_NO_AUTOEN flag rather than separate irq_disable()

Quoted 12 lines · On Sun, 4 Apr 2021 21:20:21 +0200 Krzysztof Kozlowski…
Quoted 8 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Disabling an irq before the driver has actually atempted to request it may work, but is definitely not as clean as just requesting it as normal but with the auto enable disabled.

Cc Krzysztof Kozlowski <[email protected]>
Quoted 4 lines

Best regards,
Krzysztof

Applied to the togreg branch of iio.git and pushed out as testing to let the autobuilders poke at it.

Thanks,

Jonathan

author maintainer
#8 lore raw

PATCH 3/7 iio:adc:nau7802: Use IRQF_NO_AUTOEN instead of request then disable

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Whilst a race during interrupt enabling is probably not a problem, it is better to not enable the interrupt at all. The new IRQF_NO_AUTOEN flag allows us to do that.

Cc Alexandre Belloni <[email protected]>
---
 drivers/iio/adc/nau7802.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/nau7802.c +3 -3
index 07c85434b568..bb70b51d25b1 100644
@@ -498,7 +498,8 @@ static int nau7802_probe(struct i2c_client *client,
 		ret = request_threaded_irq(client->irq,
 				NULL,
 				nau7802_eoc_trigger,
-				IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+				IRQF_TRIGGER_HIGH | IRQF_ONESHOT |
+				IRQF_NO_AUTOEN,
 				client->dev.driver->name,
 				indio_dev);
 		if (ret) {
@@ -513,8 +514,7 @@ static int nau7802_probe(struct i2c_client *client,
 			dev_info(&client->dev,
 				"Failed to allocate IRQ, using polling mode\n");
 			client->irq = 0;
-		} else
-			disable_irq(client->irq);
+		}
 	}
 
 	if (!client->irq) {
Signature · 1 line
2.31.1
Reviewed-by on v1 3/7
#9 lore raw

RE: [PATCH 3/7] iio:adc:nau7802: Use IRQF_NO_AUTOEN instead of request then disable

Quoted 14 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Alexandre Belloni <[email protected]>
Subject: [PATCH 3/7] iio:adc:nau7802: Use IRQF_NO_AUTOEN instead of request then disable

From: Jonathan Cameron <[email protected]>

Quoted 7 lines

Whilst a race during interrupt enabling is probably not a problem, it is better to not enable the interrupt at all. The new IRQF_NO_AUTOEN flag allows us to do that.

Cc Alexandre Belloni <[email protected]>

---

Quoted 29 lines
 drivers/iio/adc/nau7802.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/nau7802.c +3 -4
index 07c85434b568..bb70b51d25b1 100644
@@ -498,7 +498,8 @@ static int nau7802_probe(struct i2c_client *client,
 		ret = request_threaded_irq(client->irq,
 				NULL,
 				nau7802_eoc_trigger,
-				IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+				IRQF_TRIGGER_HIGH | IRQF_ONESHOT |
+				IRQF_NO_AUTOEN,
 				client->dev.driver->name,
 				indio_dev);
 		if (ret) {
@@ -513,8 +514,7 @@ static int nau7802_probe(struct i2c_client *client,
 			dev_info(&client->dev,
 				"Failed to allocate IRQ, using polling mode\n");
 			client->irq = 0;
-		} else
-			disable_irq(client->irq);
+		}
 	}
 
 	if (!client->irq) {
--

2.31.1

author maintainer
#10 lore raw

Re: [PATCH 3/7] iio:adc:nau7802: Use IRQF_NO_AUTOEN instead of request then disable

Quoted 16 lines · On Fri, 2 Apr 2021 20:12:13 +0000 "Song Bao Hua (Barry Song)"…
Quoted 16 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Alexandre Belloni <[email protected]>
Subject: [PATCH 3/7] iio:adc:nau7802: Use IRQF_NO_AUTOEN instead of request then disable

From: Jonathan Cameron <[email protected]>

Whilst a race during interrupt enabling is probably not a problem, it is better to not enable the interrupt at all. The new IRQF_NO_AUTOEN flag allows us to do that.

Quoted 5 lines
Quoted 3 lines
Cc Alexandre Belloni <[email protected]>

---

Applied and pushed out as testing to let the autobuilders test it a bit. Still time for others to respond though as I can rebase for at least the next few days as I expect I'll do a pull request mid week.

Thanks,

Jonathan

Quoted 31 lines
Quoted 30 lines
 drivers/iio/adc/nau7802.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/nau7802.c +3 -4
index 07c85434b568..bb70b51d25b1 100644
@@ -498,7 +498,8 @@ static int nau7802_probe(struct i2c_client *client,
 		ret = request_threaded_irq(client->irq,
 				NULL,
 				nau7802_eoc_trigger,
-				IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+				IRQF_TRIGGER_HIGH | IRQF_ONESHOT |
+				IRQF_NO_AUTOEN,
 				client->dev.driver->name,
 				indio_dev);
 		if (ret) {
@@ -513,8 +514,7 @@ static int nau7802_probe(struct i2c_client *client,
 			dev_info(&client->dev,
 				"Failed to allocate IRQ, using polling mode\n");
 			client->irq = 0;
-		} else
-			disable_irq(client->irq);
+		}
 	}
 
 	if (!client->irq) {
--

2.31.1

author maintainer
#11 lore raw

PATCH 4/7 iio:adc:sun4i-gpadc: Use new IRQF_NO_AUTOEN flag instead of request then disable

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This new flag ensures a requested irq is not autoenabled, thus removing the need for the disable_irq() that follows and closing off any chance of spurious interrupts.

---
 drivers/iio/adc/sun4i-gpadc-iio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/sun4i-gpadc-iio.c +2 -2
index 99b43f28e879..2d393a4dfff6 100644
@@ -470,7 +470,8 @@ static int sun4i_irq_init(struct platform_device *pdev, const char *name,
 	}
 
 	*irq = ret;
-	ret = devm_request_any_context_irq(&pdev->dev, *irq, handler, 0,
+	ret = devm_request_any_context_irq(&pdev->dev, *irq, handler,
+					   IRQF_NO_AUTOEN,
 					   devname, info);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "could not request %s interrupt: %d\n",
@@ -478,7 +479,6 @@ static int sun4i_irq_init(struct platform_device *pdev, const char *name,
 		return ret;
 	}
 
-	disable_irq(*irq);
 	atomic_set(atomic, 0);
 
 	return 0;
Signature · 1 line
2.31.1
Reviewed-by on v1 4/7
#12 lore raw

RE: [PATCH 4/7] iio:adc:sun4i-gpadc: Use new IRQF_NO_AUTOEN flag instead of request then disable

Quoted 13 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Maxime Ripard <[email protected]>
Subject: [PATCH 4/7] iio:adc:sun4i-gpadc: Use new IRQF_NO_AUTOEN flag instead of request then disable

From: Jonathan Cameron <[email protected]>

Quoted 7 lines

This new flag ensures a requested irq is not autoenabled, thus removing the need for the disable_irq() that follows and closing off any chance of spurious interrupts.

---

Quoted 30 lines
 drivers/iio/adc/sun4i-gpadc-iio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/sun4i-gpadc-iio.c +2 -1
index 99b43f28e879..2d393a4dfff6 100644
@@ -470,7 +470,8 @@ static int sun4i_irq_init(struct platform_device *pdev,
 const char *name,
 	}
 
 	*irq = ret;
-	ret = devm_request_any_context_irq(&pdev->dev, *irq, handler, 0,
+	ret = devm_request_any_context_irq(&pdev->dev, *irq, handler,
+					   IRQF_NO_AUTOEN,
 					   devname, info);
 	if (ret < 0) {
drivers/iio/adc/sun4i-gpadc-iio.c +0 -1
 		dev_err(&pdev->dev, "could not request %s interrupt: %d\n",
@@ -478,7 +479,6 @@ static int sun4i_irq_init(struct platform_device *pdev,
 const char *name,
 		return ret;
 	}
 
-	disable_irq(*irq);
 	atomic_set(atomic, 0);
 

return 0;
--
2.31.1

author maintainer
#13 lore raw

Re: [PATCH 4/7] iio:adc:sun4i-gpadc: Use new IRQF_NO_AUTOEN flag instead of request then disable

Quoted 15 lines · On Fri, 2 Apr 2021 20:13:00 +0000 "Song Bao Hua (Barry Song)"…
Quoted 15 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Maxime Ripard <[email protected]>
Subject: [PATCH 4/7] iio:adc:sun4i-gpadc: Use new IRQF_NO_AUTOEN flag instead of request then disable

From: Jonathan Cameron <[email protected]>

This new flag ensures a requested irq is not autoenabled, thus removing the need for the disable_irq() that follows and closing off any chance of spurious interrupts.

Quoted 5 lines
Quoted 3 lines

---

Applied to the togreg branch of iio.git and pushed out as testing
to let 0-day poke at it. Other feedback whilst it's doing that
most welcome.

Thanks,

Jonathan

Quoted 32 lines
Quoted 31 lines
 drivers/iio/adc/sun4i-gpadc-iio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/sun4i-gpadc-iio.c +2 -1
index 99b43f28e879..2d393a4dfff6 100644
@@ -470,7 +470,8 @@ static int sun4i_irq_init(struct platform_device *pdev,
 const char *name,
 	}
 
 	*irq = ret;
-	ret = devm_request_any_context_irq(&pdev->dev, *irq, handler, 0,
+	ret = devm_request_any_context_irq(&pdev->dev, *irq, handler,
+					   IRQF_NO_AUTOEN,
 					   devname, info);
 	if (ret < 0) {
drivers/iio/adc/sun4i-gpadc-iio.c +0 -1
 		dev_err(&pdev->dev, "could not request %s interrupt: %d\n",
@@ -478,7 +479,6 @@ static int sun4i_irq_init(struct platform_device *pdev,
 const char *name,
 		return ret;
 	}
 
-	disable_irq(*irq);
 	atomic_set(atomic, 0);
 

return 0;
--
2.31.1

author maintainer
#14 lore raw

PATCH 5/7 iio:chemical:scd30: Use IRQF_NO_AUTOEN to avoid irq request then disable

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This new flag cleanly avoids the need for a dance where we request the interrupt only to immediately disabling it by ensuring it is not auto-enabled in the first place.

---
 drivers/iio/chemical/scd30_core.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/iio/chemical/scd30_core.c +8 -8
index 261c277ac4a5..d89f117dd0ef 100644
@@ -655,19 +655,19 @@ static int scd30_setup_trigger(struct iio_dev *indio_dev)
 
 	indio_dev->trig = iio_trigger_get(trig);
 
+	/*
+	 * Interrupt is enabled just before taking a fresh measurement
+	 * and disabled afterwards. This means we need to ensure it is not
+	 * enabled here to keep calls to enable/disable balanced.
+	 */
 	ret = devm_request_threaded_irq(dev, state->irq, scd30_irq_handler,
-					scd30_irq_thread_handler, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+					scd30_irq_thread_handler,
+					IRQF_TRIGGER_HIGH | IRQF_ONESHOT |
+					IRQF_NO_AUTOEN,
 					indio_dev->name, indio_dev);
 	if (ret)
 		dev_err(dev, "failed to request irq\n");
 
-	/*
-	 * Interrupt is enabled just before taking a fresh measurement
-	 * and disabled afterwards. This means we need to disable it here
-	 * to keep calls to enable/disable balanced.
-	 */
-	disable_irq(state->irq);
-
 	return ret;
 }
 
Signature · 1 line
2.31.1
Reviewed-by on v1 5/7
#15 lore raw

RE: [PATCH 5/7] iio:chemical:scd30: Use IRQF_NO_AUTOEN to avoid irq request then disable

Quoted 14 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Tomasz Duszynski <[email protected]>
Subject: [PATCH 5/7] iio:chemical:scd30: Use IRQF_NO_AUTOEN to avoid irq request then disable

From: Jonathan Cameron <[email protected]>

Quoted 7 lines

This new flag cleanly avoids the need for a dance where we request the interrupt only to immediately disabling it by ensuring it is not auto-enabled in the first place.

---

Quoted 38 lines
 drivers/iio/chemical/scd30_core.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/iio/chemical/scd30_core.c +8 -9
index 261c277ac4a5..d89f117dd0ef 100644
@@ -655,19 +655,19 @@ static int scd30_setup_trigger(struct iio_dev *indio_dev)
 
 	indio_dev->trig = iio_trigger_get(trig);
 
+	/*
+	 * Interrupt is enabled just before taking a fresh measurement
+	 * and disabled afterwards. This means we need to ensure it is not
+	 * enabled here to keep calls to enable/disable balanced.
+	 */
 	ret = devm_request_threaded_irq(dev, state->irq, scd30_irq_handler,
-					scd30_irq_thread_handler, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+					scd30_irq_thread_handler,
+					IRQF_TRIGGER_HIGH | IRQF_ONESHOT |
+					IRQF_NO_AUTOEN,
 					indio_dev->name, indio_dev);
 	if (ret)
 		dev_err(dev, "failed to request irq\n");
 
-	/*
-	 * Interrupt is enabled just before taking a fresh measurement
-	 * and disabled afterwards. This means we need to disable it here
-	 * to keep calls to enable/disable balanced.
-	 */
-	disable_irq(state->irq);
-
 	return ret;
 }
 
--

2.31.1

author maintainer
#16 lore raw

Re: [PATCH 5/7] iio:chemical:scd30: Use IRQF_NO_AUTOEN to avoid irq request then disable

Quoted 16 lines · On Fri, 2 Apr 2021 20:14:04 +0000 "Song Bao Hua (Barry Song)"…
Quoted 16 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Tomasz Duszynski <[email protected]>
Subject: [PATCH 5/7] iio:chemical:scd30: Use IRQF_NO_AUTOEN to avoid irq request then disable

From: Jonathan Cameron <[email protected]>

This new flag cleanly avoids the need for a dance where we request the interrupt only to immediately disabling it by ensuring it is not auto-enabled in the first place.

Quoted 5 lines
Quoted 3 lines

---

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at it. Whilst they are doing that, any additional feedback welcomed.

Thanks,

Jonathan

Quoted 40 lines
Quoted 39 lines
 drivers/iio/chemical/scd30_core.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/iio/chemical/scd30_core.c +8 -9
index 261c277ac4a5..d89f117dd0ef 100644
@@ -655,19 +655,19 @@ static int scd30_setup_trigger(struct iio_dev *indio_dev)
 
 	indio_dev->trig = iio_trigger_get(trig);
 
+	/*
+	 * Interrupt is enabled just before taking a fresh measurement
+	 * and disabled afterwards. This means we need to ensure it is not
+	 * enabled here to keep calls to enable/disable balanced.
+	 */
 	ret = devm_request_threaded_irq(dev, state->irq, scd30_irq_handler,
-					scd30_irq_thread_handler, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+					scd30_irq_thread_handler,
+					IRQF_TRIGGER_HIGH | IRQF_ONESHOT |
+					IRQF_NO_AUTOEN,
 					indio_dev->name, indio_dev);
 	if (ret)
 		dev_err(dev, "failed to request irq\n");
 
-	/*
-	 * Interrupt is enabled just before taking a fresh measurement
-	 * and disabled afterwards. This means we need to disable it here
-	 * to keep calls to enable/disable balanced.
-	 */
-	disable_irq(state->irq);
-
 	return ret;
 }
 
--

2.31.1

author maintainer
#17 lore raw

PATCH 6/7 iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This is a bit involved as the adis library code already has some sanity checking of the flags of the requested irq that we need to ensure is happy to pass through the IRQF_NO_AUTOEN flag untouched.

Using this flag avoids us autoenabling the irq in the adis16460 and adis16475 drivers which cover parts that don't have any means of masking the interrupt on the device end.

Note, compile tested only!

Cc Alexandru Ardelean <[email protected]>
Cc Nuno Sa <[email protected]>
---
 drivers/iio/imu/adis16460.c    |  4 ++--
 drivers/iio/imu/adis16475.c    |  5 +++--
 drivers/iio/imu/adis_trigger.c | 11 ++++++-----
 3 files changed, 11 insertions(+), 9 deletions(-)
drivers/iio/imu/adis16460.c +2 -2
index 74a161e39733..73bf45e859b8 100644
@@ -403,12 +403,12 @@ static int adis16460_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
+	/* We cannot mask the interrupt, so ensure it isn't auto enabled */
+	st->adis.irq_flag |= IRQF_NO_AUTOEN;
 	ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev, NULL);
 	if (ret)
 		return ret;
 
-	adis16460_enable_irq(&st->adis, 0);
-
 	ret = __adis_initial_startup(&st->adis);
 	if (ret)
 		return ret;
drivers/iio/imu/adis16475.c +3 -2
index 8f6bea4b6608..1de62fc79e0f 100644
@@ -1258,6 +1258,9 @@ static int adis16475_config_irq_pin(struct adis16475 *st)
 		return -EINVAL;
 	}
 
+	/* We cannot mask the interrupt so ensure it's not enabled at request */
+	st->adis.irq_flag |= IRQF_NO_AUTOEN;
+
 	val = ADIS16475_MSG_CTRL_DR_POL(polarity);
 	ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
 				 ADIS16475_MSG_CTRL_DR_POL_MASK, val);
@@ -1362,8 +1365,6 @@ static int adis16475_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	adis16475_enable_irq(&st->adis, false);
-
 	ret = devm_iio_device_register(&spi->dev, indio_dev);
 	if (ret)
 		return ret;
drivers/iio/imu/adis_trigger.c +6 -5
index 0f29e56200af..39b50d6fdb6a 100644
@@ -29,18 +29,19 @@ static const struct iio_trigger_ops adis_trigger_ops = {
 
 static int adis_validate_irq_flag(struct adis *adis)
 {
+	unsigned long direction = adis->irq_flag & IRQF_TRIGGER_MASK;
 	/*
 	 * Typically this devices have data ready either on the rising edge or
 	 * on the falling edge of the data ready pin. This checks enforces that
 	 * one of those is set in the drivers... It defaults to
-	 * IRQF_TRIGGER_RISING for backward compatibility wiht devices that
+	 * IRQF_TRIGGER_RISING for backward compatibility with devices that
 	 * don't support changing the pin polarity.
 	 */
-	if (!adis->irq_flag) {
-		adis->irq_flag = IRQF_TRIGGER_RISING;
+	if (!direction) {
+		adis->irq_flag |= IRQF_TRIGGER_RISING;
 		return 0;
-	} else if (adis->irq_flag != IRQF_TRIGGER_RISING &&
-		   adis->irq_flag != IRQF_TRIGGER_FALLING) {
+	} else if (direction != IRQF_TRIGGER_RISING &&
+		   direction != IRQF_TRIGGER_FALLING) {
 		dev_err(&adis->spi->dev, "Invalid IRQ mask: %08lx\n",
 			adis->irq_flag);
 		return -EINVAL;
Signature · 1 line
2.31.1
Reviewed-by on v1 6/7
#18 lore raw

RE: [PATCH 6/7] iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable

Quoted 85 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Alexandru Ardelean <[email protected]>; Nuno Sa <[email protected]>
Subject: [PATCH 6/7] iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable

From: Jonathan Cameron <[email protected]>

This is a bit involved as the adis library code already has some sanity checking of the flags of the requested irq that we need to ensure is happy to pass through the IRQF_NO_AUTOEN flag untouched.

Using this flag avoids us autoenabling the irq in the adis16460 and adis16475 drivers which cover parts that don't have any means of masking the interrupt on the device end.

Note, compile tested only!

Cc Alexandru Ardelean <[email protected]>
Cc Nuno Sa <[email protected]>
---
 drivers/iio/imu/adis16460.c    |  4 ++--
 drivers/iio/imu/adis16475.c    |  5 +++--
 drivers/iio/imu/adis_trigger.c | 11 ++++++-----
 3 files changed, 11 insertions(+), 9 deletions(-)
drivers/iio/imu/adis16460.c +2 -2
index 74a161e39733..73bf45e859b8 100644
@@ -403,12 +403,12 @@ static int adis16460_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
+	/* We cannot mask the interrupt, so ensure it isn't auto enabled */
+	st->adis.irq_flag |= IRQF_NO_AUTOEN;
 	ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev, NULL);
 	if (ret)
 		return ret;
 
-	adis16460_enable_irq(&st->adis, 0);
-
 	ret = __adis_initial_startup(&st->adis);
 	if (ret)
 		return ret;
drivers/iio/imu/adis16475.c +3 -2
index 8f6bea4b6608..1de62fc79e0f 100644
@@ -1258,6 +1258,9 @@ static int adis16475_config_irq_pin(struct adis16475 *st)
 		return -EINVAL;
 	}
 
+	/* We cannot mask the interrupt so ensure it's not enabled at request */
+	st->adis.irq_flag |= IRQF_NO_AUTOEN;
+
 	val = ADIS16475_MSG_CTRL_DR_POL(polarity);
 	ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
 				 ADIS16475_MSG_CTRL_DR_POL_MASK, val);
@@ -1362,8 +1365,6 @@ static int adis16475_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	adis16475_enable_irq(&st->adis, false);
-
 	ret = devm_iio_device_register(&spi->dev, indio_dev);
 	if (ret)
 		return ret;
drivers/iio/imu/adis_trigger.c +1 -0
index 0f29e56200af..39b50d6fdb6a 100644
@@ -29,18 +29,19 @@ static const struct iio_trigger_ops adis_trigger_ops = {
 
 static int adis_validate_irq_flag(struct adis *adis)
 {
+	unsigned long direction = adis->irq_flag & IRQF_TRIGGER_MASK;
 	/*

drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops adis_trigger_ops = { · line 40

Quoted 10 lines
drivers/iio/imu/adis_trigger.c +2 -3
 	 * Typically this devices have data ready either on the rising edge or
 	 * on the falling edge of the data ready pin. This checks enforces that
 	 * one of those is set in the drivers... It defaults to
-	 * IRQF_TRIGGER_RISING for backward compatibility wiht devices that
+	 * IRQF_TRIGGER_RISING for backward compatibility with devices that
 	 * don't support changing the pin polarity.
 	 */
-	if (!adis->irq_flag) {
-		adis->irq_flag = IRQF_TRIGGER_RISING;
+	if (!direction) {

Though a better way might be:

if (direction == IRQF_TRIGGER_NONE)

Quoted 11 lines
drivers/iio/imu/adis_trigger.c +3 -3
+		adis->irq_flag |= IRQF_TRIGGER_RISING;
 		return 0;
-	} else if (adis->irq_flag != IRQF_TRIGGER_RISING &&
-		   adis->irq_flag != IRQF_TRIGGER_FALLING) {
+	} else if (direction != IRQF_TRIGGER_RISING &&
+		   direction != IRQF_TRIGGER_FALLING) {
 		dev_err(&adis->spi->dev, "Invalid IRQ mask: %08lx\n",
 			adis->irq_flag);
 		return -EINVAL;
--

2.31.1

Thanks
Barry

author maintainer
#19 lore raw

Re: [PATCH 6/7] iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable

Quoted 96 lines · On Fri, 2 Apr 2021 20:37:37 +0000 "Song Bao Hua (Barry Song)"…
Quoted 83 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Alexandru Ardelean <[email protected]>; Nuno Sa <[email protected]>
Subject: [PATCH 6/7] iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable

From: Jonathan Cameron <[email protected]>

This is a bit involved as the adis library code already has some sanity checking of the flags of the requested irq that we need to ensure is happy to pass through the IRQF_NO_AUTOEN flag untouched.

Using this flag avoids us autoenabling the irq in the adis16460 and adis16475 drivers which cover parts that don't have any means of masking the interrupt on the device end.

Note, compile tested only!

Cc Alexandru Ardelean <[email protected]>
Cc Nuno Sa <[email protected]>
---
 drivers/iio/imu/adis16460.c    |  4 ++--
 drivers/iio/imu/adis16475.c    |  5 +++--
 drivers/iio/imu/adis_trigger.c | 11 ++++++-----
 3 files changed, 11 insertions(+), 9 deletions(-)
drivers/iio/imu/adis16460.c +2 -2
index 74a161e39733..73bf45e859b8 100644
@@ -403,12 +403,12 @@ static int adis16460_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
+	/* We cannot mask the interrupt, so ensure it isn't auto enabled */
+	st->adis.irq_flag |= IRQF_NO_AUTOEN;
 	ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev, NULL);
 	if (ret)
 		return ret;
 
-	adis16460_enable_irq(&st->adis, 0);
-
 	ret = __adis_initial_startup(&st->adis);
 	if (ret)
 		return ret;
drivers/iio/imu/adis16475.c +3 -2
index 8f6bea4b6608..1de62fc79e0f 100644
@@ -1258,6 +1258,9 @@ static int adis16475_config_irq_pin(struct adis16475 *st)
 		return -EINVAL;
 	}
 
+	/* We cannot mask the interrupt so ensure it's not enabled at request */
+	st->adis.irq_flag |= IRQF_NO_AUTOEN;
+
 	val = ADIS16475_MSG_CTRL_DR_POL(polarity);
 	ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
 				 ADIS16475_MSG_CTRL_DR_POL_MASK, val);
@@ -1362,8 +1365,6 @@ static int adis16475_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	adis16475_enable_irq(&st->adis, false);
-
 	ret = devm_iio_device_register(&spi->dev, indio_dev);
 	if (ret)
 		return ret;
drivers/iio/imu/adis_trigger.c +1 -0
index 0f29e56200af..39b50d6fdb6a 100644
@@ -29,18 +29,19 @@ static const struct iio_trigger_ops adis_trigger_ops = {
 
 static int adis_validate_irq_flag(struct adis *adis)
 {
+	unsigned long direction = adis->irq_flag & IRQF_TRIGGER_MASK;
 	/*

drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops adis_trigger_ops = { · line 40

Quoted 10 lines
drivers/iio/imu/adis_trigger.c +2 -3
 	 * Typically this devices have data ready either on the rising edge or
 	 * on the falling edge of the data ready pin. This checks enforces that
 	 * one of those is set in the drivers... It defaults to
-	 * IRQF_TRIGGER_RISING for backward compatibility wiht devices that
+	 * IRQF_TRIGGER_RISING for backward compatibility with devices that
 	 * don't support changing the pin polarity.
 	 */
-	if (!adis->irq_flag) {
-		adis->irq_flag = IRQF_TRIGGER_RISING;
+	if (!direction) {  
Quoted 3 lines

Though a better way might be:

if (direction == IRQF_TRIGGER_NONE)

Agreed. That makes it a tiny bit more obvious what is going on.

Applied with that change (seems unlikely to affect other's tags) to the togreg branch of iio.git and pushed out as testing for the autobuilders to see if they can find anything we missed.

As normal, whilst 0-day and friends are working their magic, there is time for any additional feedback anyone would like to share.

Thanks,

Jonathan

Quoted 16 lines
Quoted 11 lines
drivers/iio/imu/adis_trigger.c +3 -3
+		adis->irq_flag |= IRQF_TRIGGER_RISING;
 		return 0;
-	} else if (adis->irq_flag != IRQF_TRIGGER_RISING &&
-		   adis->irq_flag != IRQF_TRIGGER_FALLING) {
+	} else if (direction != IRQF_TRIGGER_RISING &&
+		   direction != IRQF_TRIGGER_FALLING) {
 		dev_err(&adis->spi->dev, "Invalid IRQ mask: %08lx\n",
 			adis->irq_flag);
 		return -EINVAL;
--
Quoted 1 line

2.31.1

Thanks
Barry

maintainer Reviewed-by
#20 lore raw

RE: [PATCH 6/7] iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable

Quoted 134 lines

From: Jonathan Cameron <[email protected]>
Sent: Monday, April 5, 2021 4:41 PM
To: Song Bao Hua (Barry Song) <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; Alexandru Ardelean <[email protected]>; Sa, Nuno <[email protected]>; tiantao (H) <[email protected]>
Subject: Re: [PATCH 6/7] iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable

Quoted 5 lines · On Fri, 2 Apr 2021 20:37:37 +0000 "Song Bao Hua (Barry Song)"…
Quoted 5 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>;

Jonathan Cameron

Quoted 1 line
Quoted 1 line

<[email protected]>; Alexandru Ardelean

<[email protected]>;

Quoted 2 lines
Quoted 2 lines

Nuno Sa <[email protected]>
Subject: [PATCH 6/7] iio:imu:adis: Use IRQF_NO_AUTOEN instead

of irq request

Quoted 7 lines
Quoted 7 lines

then disable

From: Jonathan Cameron <[email protected]>

This is a bit involved as the adis library code already has some sanity checking of the flags of the requested irq that we need to ensure is happy to pass through the IRQF_NO_AUTOEN flag

untouched.

Quoted 8 lines
Quoted 8 lines

Using this flag avoids us autoenabling the irq in the adis16460 and adis16475 drivers which cover parts that don't have any means of masking the interrupt on the device end.

Note, compile tested only!

Signed-off-by Jonathan Cameron

<[email protected]>

Quoted 9 lines

Review

Quoted 9 lines
Cc Alexandru Ardelean <[email protected]>
Cc Nuno Sa <[email protected]>
---
 drivers/iio/imu/adis16460.c    |  4 ++--
 drivers/iio/imu/adis16475.c    |  5 +++--
 drivers/iio/imu/adis_trigger.c | 11 ++++++-----
 3 files changed, 11 insertions(+), 9 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/imu/adis16460.c

Quoted 4 lines

drivers/iio/imu/adis16460.c static int adis16460_probe(struct

Quoted 4 lines

index 74a161e39733..73bf45e859b8 100644

drivers/iio/imu/adis16460.c +0 -0
@@ -403,12 +403,12 @@ static int adis16460_probe(struct

spi_device *spi)

Quoted 4 lines

drivers/iio/imu/adis16460.c static int adis16460_probe(struct spi_device *spi)

Quoted 4 lines
drivers/iio/imu/adis16460.c +1 -0
 	if (ret)
 		return ret;
 
+	/* We cannot mask the interrupt, so ensure it isn't auto

enabled */

Quoted 2 lines

drivers/iio/imu/adis16460.c static int adis16460_probe(struct · line 408

Quoted 2 lines
drivers/iio/imu/adis16460.c +1 -0
+	st->adis.irq_flag |= IRQF_NO_AUTOEN;
 	ret = devm_adis_setup_buffer_and_trigger(&st->adis,

indio_dev, NULL);

Quoted 9 lines

Review

Quoted 9 lines
drivers/iio/imu/adis16460.c +0 -2
 	if (ret)
 		return ret;
 
-	adis16460_enable_irq(&st->adis, 0);
-
 	ret = __adis_initial_startup(&st->adis);
 	if (ret)
 		return ret;
(quoted diff) +0 -0

b/drivers/iio/imu/adis16475.c

Quoted 4 lines

drivers/iio/imu/adis16475.c static int adis16475_config_irq_pin(struct

Quoted 4 lines

index 8f6bea4b6608..1de62fc79e0f 100644

drivers/iio/imu/adis16475.c +0 -0
@@ -1258,6 +1258,9 @@ static int adis16475_config_irq_pin(struct

adis16475 *st)

Quoted 4 lines

drivers/iio/imu/adis16475.c static int adis16475_config_irq_pin(struct adis16475 *st)

Quoted 4 lines
drivers/iio/imu/adis16475.c +1 -0
 		return -EINVAL;
 	}
 
+	/* We cannot mask the interrupt so ensure it's not enabled at

request */

Quoted 4 lines

drivers/iio/imu/adis16475.c static int adis16475_config_irq_pin(struct adis16475 *st)

Quoted 4 lines
drivers/iio/imu/adis16475.c +2 -0
+	st->adis.irq_flag |= IRQF_NO_AUTOEN;
+
 	val = ADIS16475_MSG_CTRL_DR_POL(polarity);
 	ret = __adis_update_bits(&st->adis,

ADIS16475_REG_MSG_CTRL,

Quoted 1 line
Quoted 1 line

ADIS16475_MSG_CTRL_DR_POL_MASK, val);

Quoted 1 line

drivers/iio/imu/adis16475.c static int adis16475_probe(struct

Quoted 1 line
drivers/iio/imu/adis16475.c +0 -0
@@ -1362,8 +1365,6 @@ static int adis16475_probe(struct

spi_device *spi)

Quoted 9 lines

Review

Quoted 9 lines
drivers/iio/imu/adis16475.c +0 -2
 	if (ret)
 		return ret;
 
-	adis16475_enable_irq(&st->adis, false);
-
 	ret = devm_iio_device_register(&spi->dev, indio_dev);
 	if (ret)
 		return ret;
(quoted diff) +0 -0

b/drivers/iio/imu/adis_trigger.c

Quoted 4 lines

drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops

Quoted 4 lines

index 0f29e56200af..39b50d6fdb6a 100644

drivers/iio/imu/adis_trigger.c +0 -0
@@ -29,18 +29,19 @@ static const struct iio_trigger_ops

adis_trigger_ops = {

Quoted 4 lines

drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops adis_trigger_ops = {

Quoted 4 lines
drivers/iio/imu/adis_trigger.c +1 -0
 static int adis_validate_irq_flag(struct adis *adis)
 {
+	unsigned long direction = adis->irq_flag &

IRQF_TRIGGER_MASK;

Quoted 2 lines

drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops · line 33

Quoted 2 lines
drivers/iio/imu/adis_trigger.c +0 -0
 	/*
 	 * Typically this devices have data ready either on the rising

edge or

Quoted 1 line

drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops · line 34

Quoted 1 line
drivers/iio/imu/adis_trigger.c +0 -0
 	 * on the falling edge of the data ready pin. This checks

enforces that

Quoted 2 lines

drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops · line 35

Quoted 2 lines
drivers/iio/imu/adis_trigger.c +0 -1
 	 * one of those is set in the drivers... It defaults to
-	 * IRQF_TRIGGER_RISING for backward compatibility wiht

devices that

Quoted 1 line

drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops · line 36

Quoted 1 line
drivers/iio/imu/adis_trigger.c +1 -0
+	 * IRQF_TRIGGER_RISING for backward compatibility with

devices that

Quoted 11 lines

drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops adis_trigger_ops = { · line 40

Quoted 5 lines
drivers/iio/imu/adis_trigger.c +1 -2
 	 * don't support changing the pin polarity.
 	 */
-	if (!adis->irq_flag) {
-		adis->irq_flag = IRQF_TRIGGER_RISING;
+	if (!direction) {

Though a better way might be:

if (direction == IRQF_TRIGGER_NONE)

Quoted 8 lines

Agreed. That makes it a tiny bit more obvious what is going on.

Applied with that change (seems unlikely to affect other's tags) to the togreg branch of iio.git and pushed out as testing for the autobuilders to see if they can find anything we missed.

As normal, whilst 0-day and friends are working their magic, there is time for any additional feedback anyone would like to share.

If not too late :)...

author maintainer
#21 lore raw

PATCH 7/7 iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and disable

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

These devices are not able to mask the signal used as a data ready interrupt. As such they previously requested the irq then immediately disabled it. Now we can avoid the potential of a spurious interrupt by avoiding the irq being auto enabled in the first place.

I'm not sure how this code could have been called with the irq already disabled, so I believe the conditional would always have been true and have removed it.

Cc Lars-Peter Clausen <[email protected]>
Cc Alexandru Ardelean <[email protected]>
---
 drivers/iio/adc/ad_sigma_delta.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/adc/ad_sigma_delta.c +2 -5
index 9289812c0a94..e777ec718973 100644
@@ -485,18 +485,15 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
 	sigma_delta->trig->ops = &ad_sd_trigger_ops;
 	init_completion(&sigma_delta->completion);
 
+	sigma_delta->irq_dis = true;
 	ret = request_irq(sigma_delta->spi->irq,
 			  ad_sd_data_rdy_trig_poll,
-			  sigma_delta->info->irq_flags,
+			  sigma_delta->info->irq_flags | IRQF_NO_AUTOEN,
 			  indio_dev->name,
 			  sigma_delta);
 	if (ret)
 		goto error_free_trig;
 
-	if (!sigma_delta->irq_dis) {
-		sigma_delta->irq_dis = true;
-		disable_irq_nosync(sigma_delta->spi->irq);
-	}
 	iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta);
 
 	ret = iio_trigger_register(sigma_delta->trig);
Signature · 1 line
2.31.1
#22 lore raw

RE: [PATCH 7/7] iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and disable

Quoted 14 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Alexandru Ardelean <[email protected]>
Subject: [PATCH 7/7] iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and disable

From: Jonathan Cameron <[email protected]>

Quoted 9 lines

These devices are not able to mask the signal used as a data ready interrupt. As such they previously requested the irq then immediately disabled it. Now we can avoid the potential of a spurious interrupt by avoiding the irq being auto enabled in the first place.

I'm not sure how this code could have been called with the irq already disabled, so I believe the conditional would always have been true and have removed it.

If irq_dis is true, it seems the original code assumed interrupt was open. Now the code is moving to disable-irq for true irq_dis. For false irq_dis, this patch has no side effect so looks correct.

A safer way might be as below?

if(!sigma_delta->irq_dis)

	irq_flags = sigma_delta->info->irq_flags | IRQF_NO_AUTOEN;

request_irq(irq_flags);

sigma_delta->irq_dis = true;

Quoted 34 lines
Cc Lars-Peter Clausen <[email protected]>
Cc Alexandru Ardelean <[email protected]>
---
 drivers/iio/adc/ad_sigma_delta.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/adc/ad_sigma_delta.c +2 -6
index 9289812c0a94..e777ec718973 100644
@@ -485,18 +485,15 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
 	sigma_delta->trig->ops = &ad_sd_trigger_ops;
 	init_completion(&sigma_delta->completion);
 
+	sigma_delta->irq_dis = true;
 	ret = request_irq(sigma_delta->spi->irq,
 			  ad_sd_data_rdy_trig_poll,
-			  sigma_delta->info->irq_flags,
+			  sigma_delta->info->irq_flags | IRQF_NO_AUTOEN,
 			  indio_dev->name,
 			  sigma_delta);
 	if (ret)
 		goto error_free_trig;
 
-	if (!sigma_delta->irq_dis) {
-		sigma_delta->irq_dis = true;
-		disable_irq_nosync(sigma_delta->spi->irq);
-	}
 	iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta);
 
 	ret = iio_trigger_register(sigma_delta->trig);
--
Quoted 1 line

2.31.1

Thanks
Barry

author maintainer
#23 lore raw

Re: [PATCH 7/7] iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and disable

Quoted 17 lines · On Fri, 2 Apr 2021 20:30:17 +0000 "Song Bao Hua (Barry Song)"…
Quoted 17 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Alexandru Ardelean <[email protected]>
Subject: [PATCH 7/7] iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and disable

From: Jonathan Cameron <[email protected]>

These devices are not able to mask the signal used as a data ready interrupt. As such they previously requested the irq then immediately disabled it. Now we can avoid the potential of a spurious interrupt by avoiding the irq being auto enabled in the first place.

Quoted 8 lines
Quoted 4 lines

I'm not sure how this code could have been called with the irq already disabled, so I believe the conditional would always have been true and have removed it.

If irq_dis is true, it seems the original code assumed interrupt was open. Now the code is moving to disable-irq for true irq_dis. For false irq_dis, this patch has no side effect so looks correct.

Hi Barry,

As far as I can tell (and I looked closely :), at the point where ad_sd_probe_trigger() can be called, irq_dis is always false, so the original check is misleading by implying otherwise.

Taken in isolation of what is visible in this patch I'd agree the change you suggest makes sense, but I'd also like to clean up the wrong impression the original check was giving. It is also worth noting that ad_sigma_delta.h lists irq_dis as a private member of the structure that should only be used in the library (reducing chances of any drivers in future doing something odd with it).

The other checks on irq_dis look suspicious as well, but removing those would rather spread the scope of this patch.

As Lars has given an Reviewed-by and this is his code, I'm going to press ahead with this as it stands.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to see if we missed anything.

Thanks,

Jonathan

Quoted 49 lines

A safer way might be as below?

if(!sigma_delta->irq_dis)

	irq_flags = sigma_delta->info->irq_flags | IRQF_NO_AUTOEN;

request_irq(irq_flags);

sigma_delta->irq_dis = true;

Quoted 34 lines
Cc Lars-Peter Clausen <[email protected]>
Cc Alexandru Ardelean <[email protected]>
---
 drivers/iio/adc/ad_sigma_delta.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/adc/ad_sigma_delta.c +2 -6
index 9289812c0a94..e777ec718973 100644
@@ -485,18 +485,15 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
 	sigma_delta->trig->ops = &ad_sd_trigger_ops;
 	init_completion(&sigma_delta->completion);
 
+	sigma_delta->irq_dis = true;
 	ret = request_irq(sigma_delta->spi->irq,
 			  ad_sd_data_rdy_trig_poll,
-			  sigma_delta->info->irq_flags,
+			  sigma_delta->info->irq_flags | IRQF_NO_AUTOEN,
 			  indio_dev->name,
 			  sigma_delta);
 	if (ret)
 		goto error_free_trig;
 
-	if (!sigma_delta->irq_dis) {
-		sigma_delta->irq_dis = true;
-		disable_irq_nosync(sigma_delta->spi->irq);
-	}
 	iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta);
 
 	ret = iio_trigger_register(sigma_delta->trig);
--
Quoted 1 line

2.31.1

Thanks
Barry

#24 lore raw

RE: [PATCH 7/7] iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and disable

Quoted 40 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Tuesday, April 6, 2021 2:52 AM
To: Song Bao Hua (Barry Song) <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Alexandru Ardelean <[email protected]>; tiantao (H) <[email protected]>
Subject: Re: [PATCH 7/7] iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and disable

Quoted 17 lines · On Fri, 2 Apr 2021 20:30:17 +0000 "Song Bao Hua (Barry Song)"…
Quoted 17 lines

-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Saturday, April 3, 2021 7:46 AM
To: [email protected]
Cc: Song Bao Hua (Barry Song) <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Alexandru Ardelean <[email protected]>
Subject: [PATCH 7/7] iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and disable

From: Jonathan Cameron <[email protected]>

These devices are not able to mask the signal used as a data ready interrupt. As such they previously requested the irq then immediately disabled it. Now we can avoid the potential of a spurious interrupt by avoiding the irq being auto enabled in the first place.

Quoted 8 lines
Quoted 4 lines

I'm not sure how this code could have been called with the irq already disabled, so I believe the conditional would always have been true and have removed it.

If irq_dis is true, it seems the original code assumed interrupt was open. Now the code is moving to disable-irq for true irq_dis. For false irq_dis, this patch has no side effect so looks correct.

Quoted 6 lines

Hi Barry,

As far as I can tell (and I looked closely :), at the point where ad_sd_probe_trigger() can be called, irq_dis is always false, so the original check is misleading by implying otherwise.

I didn't realize that. Thanks for clarification.

Quoted 9 lines

Taken in isolation of what is visible in this patch I'd agree the change you suggest makes sense, but I'd also like to clean up the wrong impression the original check was giving. It is also worth noting that ad_sigma_delta.h lists irq_dis as a private member of the structure that should only be used in the library (reducing chances of any drivers in future doing something odd with it).

Yes. It makes sense.

Quoted 30 lines

The other checks on irq_dis look suspicious as well, but removing those would rather spread the scope of this patch.

As Lars has given an Reviewed-by and this is his code, I'm going to press ahead with this as it stands.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to see if we missed anything.

Thanks,

Jonathan

Quoted 17 lines

A safer way might be as below?

if(!sigma_delta->irq_dis)

	irq_flags = sigma_delta->info->irq_flags | IRQF_NO_AUTOEN;

request_irq(irq_flags);

sigma_delta->irq_dis = true;

Quoted 7 lines
Cc Lars-Peter Clausen <[email protected]>
Cc Alexandru Ardelean <[email protected]>
---
 drivers/iio/adc/ad_sigma_delta.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Quoted 30 lines
Quoted 6 lines

drivers/iio/adc/ad_sigma_delta.c static int ad_sd_probe_trigger(struct iio_dev

Quoted 6 lines
drivers/iio/adc/ad_sigma_delta.c +0 -0
index 9289812c0a94..e777ec718973 100644
@@ -485,18 +485,15 @@ static int ad_sd_probe_trigger(struct iio_dev

*indio_dev)

Quoted 23 lines
Quoted 22 lines
drivers/iio/adc/ad_sigma_delta.c +2 -6
 	sigma_delta->trig->ops = &ad_sd_trigger_ops;
 	init_completion(&sigma_delta->completion);
 
+	sigma_delta->irq_dis = true;
 	ret = request_irq(sigma_delta->spi->irq,
 			  ad_sd_data_rdy_trig_poll,
-			  sigma_delta->info->irq_flags,
+			  sigma_delta->info->irq_flags | IRQF_NO_AUTOEN,
 			  indio_dev->name,
 			  sigma_delta);
 	if (ret)
 		goto error_free_trig;
 
-	if (!sigma_delta->irq_dis) {
-		sigma_delta->irq_dis = true;
-		disable_irq_nosync(sigma_delta->spi->irq);
-	}
 	iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta);
 
 	ret = iio_trigger_register(sigma_delta->trig);
--

2.31.1

Thanks
Barry

Reviewed-by on the v1 series
#25 lore raw
In reply to Jonathan Cameron
Quoted 10 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This series is dependant on
cbe16f35bee68 ("genirq: Add IRQF_NO_AUTOEN for request_irq/nmi()") which is available in an immutable tag in the tip tree.
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/tag/?h=irq-no-autoen-2021-03-25
which I'll merge in to the IIO tree if we need it before it's available upstream.

Quoted 3 lines

That patch introduces a new IRQF_NO_AUTOEN flag for irq requests to avoid the current dance where we either mark an irq as not to be autoenabled before we know if we can actually request it succesfully, or (as IIO drivers seem to

successfully

Quoted 7 lines

have gone with) we disable the interrupt just after requesting it. In short the flag stops the interrupt being autoenabled in the first place.

So this series applies this magic to IIO :)

Note these are all just compile tested and some of them aren't entirely trivial because of other aspects of the irq flag handling.

I have looked at them and indeed in all cases it's clearer now what is going on. FWIW,

Quoted 27 lines

Jonathan Cameron (7):
iio:adc:ad7766: Use new IRQF_NO_AUTOEN to reduce boilerplate iio:adc:exynos-adc: Use new IRQF_NO_AUTOEN flag rather than separate
irq_disable()
iio:adc:nau7802: Use IRQF_NO_AUTOEN instead of request then disable iio:adc:sun4i-gpadc: Use new IRQF_NO_AUTOEN flag instead of request
then disable
iio:chemical:scd30: Use IRQF_NO_AUTOEN to avoid irq request then
disable
iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable iio:adc:ad_sigma_delta: Use IRQF_NO_AUTOEN rather than request and
disable

 drivers/iio/adc/ad7766.c          | 15 +++++++--------
 drivers/iio/adc/ad_sigma_delta.c  |  7 ++-----
 drivers/iio/adc/exynos_adc.c      |  4 ++--
 drivers/iio/adc/nau7802.c         |  6 +++---
 drivers/iio/adc/sun4i-gpadc-iio.c |  4 ++--
 drivers/iio/chemical/scd30_core.c | 16 ++++++++--------
 drivers/iio/imu/adis16460.c       |  4 ++--
 drivers/iio/imu/adis16475.c       |  5 +++--
 drivers/iio/imu/adis_trigger.c    | 11 ++++++-----
 9 files changed, 35 insertions(+), 37 deletions(-)

--
2.31.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on the v1 series
#26 lore raw
In reply to Jonathan Cameron
Quoted 15 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This series is dependant on
cbe16f35bee68 ("genirq: Add IRQF_NO_AUTOEN for request_irq/nmi()") which is available in an immutable tag in the tip tree.
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/tag/?h=irq-no-autoen-2021-03-25
which I'll merge in to the IIO tree if we need it before it's available upstream.

That patch introduces a new IRQF_NO_AUTOEN flag for irq requests to avoid the current dance where we either mark an irq as not to be autoenabled before we know if we can actually request it succesfully, or (as IIO drivers seem to have gone with) we disable the interrupt just after requesting it. In short the flag stops the interrupt being autoenabled in the first place.

Quoted 4 lines

So this series applies this magic to IIO :)

Note these are all just compile tested and some of them aren't entirely trivial because of other aspects of the irq flag handling.

Something like IRQF_NO_AUTOEN has been on my wish list for a long time. Thanks Barry!

Series looks good.