[PATCH v4 next 5/6] iio: sca3000: stop interrupts via devm_add_action_or_reset()

Harshit Mogalapalli posted 6 patches 5 days, 15 hours ago
There is a newer version of this series
[PATCH v4 next 5/6] iio: sca3000: stop interrupts via devm_add_action_or_reset()
Posted by Harshit Mogalapalli 5 days, 15 hours ago
sca3000_stop_all_interrupts() is moved above the probe routine so the
new function sca3000_disable_interrupts() used in probe can directly
call it without additional declaration.

Used devm_add_action_or_reset() for shutting down the interrupts.
Make sca3000_stop_all_interrupts() return void now that it always hooks
into devm cleanup.

No functional change intended.

Suggested-by: David Lechner <dlechner@baylibre.com>
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
v3->v4: had to rebase becuase guard change is now moved earlier [Thanks
to Andy for the suggestion]
---
 drivers/iio/accel/sca3000.c | 45 ++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index a46990453ed0..c3a8f34d4852 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -1438,6 +1438,25 @@ static const struct iio_info sca3000_info = {
 	.write_event_config = &sca3000_write_event_config,
 };
 
+static void sca3000_stop_all_interrupts(void *data)
+{
+	struct iio_dev *indio_dev = data;
+	struct sca3000_state *st = iio_priv(indio_dev);
+	int ret;
+
+	guard(mutex)(&st->lock);
+
+	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
+	if (ret)
+		return;
+
+	sca3000_write_reg(st, SCA3000_REG_INT_MASK_ADDR,
+			  (st->rx[0] &
+			   ~(SCA3000_REG_INT_MASK_RING_THREE_QUARTER |
+			     SCA3000_REG_INT_MASK_RING_HALF |
+			     SCA3000_REG_INT_MASK_ALL_INTS)));
+}
+
 static int sca3000_probe(struct spi_device *spi)
 {
 	struct device *dev = &spi->dev;
@@ -1489,39 +1508,23 @@ static int sca3000_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = iio_device_register(indio_dev);
+	ret = devm_add_action_or_reset(dev, sca3000_stop_all_interrupts,
+				       indio_dev);
 	if (ret)
 		return ret;
 
-	return 0;
-}
-
-static void sca3000_stop_all_interrupts(struct sca3000_state *st)
-{
-	int ret;
-
-	guard(mutex)(&st->lock);
-
-	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
+	ret = iio_device_register(indio_dev);
 	if (ret)
-		return;
+		return ret;
 
-	sca3000_write_reg(st, SCA3000_REG_INT_MASK_ADDR,
-			  (st->rx[0] &
-			   ~(SCA3000_REG_INT_MASK_RING_THREE_QUARTER |
-			     SCA3000_REG_INT_MASK_RING_HALF |
-			     SCA3000_REG_INT_MASK_ALL_INTS)));
+	return 0;
 }
 
 static void sca3000_remove(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct sca3000_state *st = iio_priv(indio_dev);
 
 	iio_device_unregister(indio_dev);
-
-	/* Must ensure no interrupts can be generated after this! */
-	sca3000_stop_all_interrupts(st);
 }
 
 static const struct spi_device_id sca3000_id[] = {
-- 
2.47.3
Re: [PATCH v4 next 5/6] iio: sca3000: stop interrupts via devm_add_action_or_reset()
Posted by Andy Shevchenko 5 days, 12 hours ago
On Tue, Feb 03, 2026 at 10:12:00PM -0800, Harshit Mogalapalli wrote:
> sca3000_stop_all_interrupts() is moved above the probe routine so the
> new function sca3000_disable_interrupts() used in probe can directly
> call it without additional declaration.
> 
> Used devm_add_action_or_reset() for shutting down the interrupts.
> Make sca3000_stop_all_interrupts() return void now that it always hooks
> into devm cleanup.
> 
> No functional change intended.

This patch overloaded by extra thing. What you should do is just move code
upper without _any_ modifications being done _before_ even patching it for
guard()(). With that additional patch the rest will look much easier to
review.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v4 next 5/6] iio: sca3000: stop interrupts via devm_add_action_or_reset()
Posted by Harshit Mogalapalli 5 days, 12 hours ago
Hi Andy,

On 04/02/26 14:31, Andy Shevchenko wrote:
> On Tue, Feb 03, 2026 at 10:12:00PM -0800, Harshit Mogalapalli wrote:
>> sca3000_stop_all_interrupts() is moved above the probe routine so the
>> new function sca3000_disable_interrupts() used in probe can directly
>> call it without additional declaration.
>>
>> Used devm_add_action_or_reset() for shutting down the interrupts.
>> Make sca3000_stop_all_interrupts() return void now that it always hooks
>> into devm cleanup.
>>
>> No functional change intended.
> 
> This patch overloaded by extra thing. What you should do is just move code
> upper without _any_ modifications being done _before_ even patching it for
> guard()(). With that additional patch the rest will look much easier to
> review.
> 

I agree, thanks a lot for the suggestions!

Regards,
Harshit