mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Gustavo Bastos" <gustavobastos@usp.br>,
	"Andrew Ijano" <andrew.ijano@gmail.com>,
	"open list:IIO SUBSYSTEM AND DRIVERS" <linux-iio@vger.kernel.org>,
	"open list" <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	"Andy Shevchenko" <andriy.shevchenko@intel.com>
Subject: Re: [PATCH next 4/4] iio: sca3000: stop interrupts via devm_add_action_or_reset()
Date: Sat, 31 Jan 2026 23:22:24 +0530	[thread overview]
Message-ID: <464ec1bb-858d-4ff5-8fa0-1c9af9b9945e@oracle.com> (raw)
In-Reply-To: <20260131163909.7c90c9d7@jic23-huawei>

Hi Jonathan,


On 31/01/26 22:09, Jonathan Cameron wrote:
> On Fri, 30 Jan 2026 13:43:11 -0800
> Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> 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 doing the interrupts. After
>> this there is no need to have a remove call back, so got rid of the
>> remove callback.
>>
>> No functional change intended.
>>
>> Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
>> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> 
> Will need an update if you indeed didn't intend to change order in previous
> patch.  

Yes, I didn't intend that change in Patch 3.

> devm_iio_device_register() is last in vast majority of probe
> functions because it opens us up to userspace interaction. We almost
> always want to cut that off on remove before doing anything else.
> 

Sure, thanks a lot!

I have checked in other drivers while thinking about it, but my code 
base changed due to incorrect ordering in PATCH 3 :(

Maybe the best idea is to do squash PATCH3 and PATCH 4 ?

>> ---
>>   drivers/iio/accel/sca3000.c | 58 ++++++++++++++++++++-----------------
>>   1 file changed, 32 insertions(+), 26 deletions(-)
>>
>> diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
>> index bf1957c7bc77..7f7d29688a81 100644
>> --- a/drivers/iio/accel/sca3000.c
>> +++ b/drivers/iio/accel/sca3000.c
>> @@ -1437,6 +1437,34 @@ static const struct iio_info sca3000_info = {
>>   	.write_event_config = &sca3000_write_event_config,
>>   };
>>   
>> +static int sca3000_stop_all_interrupts(struct sca3000_state *st)
>> +{
>> +	int ret;
>> +
>> +	mutex_lock(&st->lock);
> 
> Use guard(mutex)(&st->lock); to simplify this. Remember to include cleanup.h
> A future patch could then make use of guard() more widely in this driver.
> 
>> +	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
>> +	if (ret)
>> +		goto error_ret;
> 
> Blank line here.  Keeps each group of action / error check clearly delineated
> if we have a blank line between them. Note this is a case of do as I say
> not as I did nearly 17 years back when I wrote this (younger me did many
> things wrong ;)
> 
> With guard() above, you can just do
> 	if (ret)
> 		return ret;
> 
> here.
>> +	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)));
> 
> With guard() above, this becomes
> 	return sca3000_write_reg();
> 
> 
>> +error_ret:
>> +	mutex_unlock(&st->lock);
>> +	return ret;
>> +}
>> +


Sure will simplify this function with scoped guards. Thanks for the 
suggestion.

>> +static void sca3000_disable_interrupts(void *data)
>> +{
>> +	struct iio_dev *indio_dev = data;
>> +	struct sca3000_state *st = iio_priv(indio_dev);
>> +
>> +	/* Must ensure no interrupts can be generated after this! */
>> +	sca3000_stop_all_interrupts(st);
>> +}
>> +
>> +
>>   static int sca3000_probe(struct spi_device *spi)
>>   {
>>   	const struct spi_device_id *id = spi_get_device_id(spi);
>> @@ -1481,6 +1509,7 @@ static int sca3000_probe(struct spi_device *spi)
>>   		if (ret)
>>   			return ret;
>>   	}
>> +
> 
> Unrelated change.  Make sure to check for these in patches before
> you send them out.  It adds noise and typically means you'll end
> up doing another version even if everything else is good.
> 

sure, I was actually aware of this new line addition while sending, 
wasn't sure if I had to do it in this or do it in a separate patch. But 
I understood that now to not mix unrelated changes.


>>   	ret = sca3000_clean_setup(st);
>>   	if (ret)
>>   		return ret;
...
>> +		return ret;
>>   
>> -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);
>> +	return devm_add_action_or_reset(dev, sca3000_disable_interrupts, indio_dev);
> As mentioned above. This looks unlikely to be a good idea as a reorder of code.
> 
> I'd expect interfaces to go away and then interrupts to be stopped. In general
> that should always be safe unless we have some racey bug somewhere in the IIO
> core or the driver is doing something unusual.
> 

Sure, so iio_device_unregister() is the first thing to happen. Will do a 
v2 trying to address all comments.


Thanks a lot for detailed review and guidance with this! I really
appreciate it.

> Thanks,
> 
> Jonathan
> 

Regards,
Harshit

      reply	other threads:[~2026-01-31 17:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-30 21:43 [PATCH next 0/4] IIO: sca3000: devm resource management Harshit Mogalapalli
2026-01-30 21:43 ` [PATCH next 1/4] iio: sca3000: cache SPI device ID in probe Harshit Mogalapalli
2026-01-31 16:28   ` Jonathan Cameron
2026-01-31 17:32     ` Harshit Mogalapalli
2026-01-30 21:43 ` [PATCH next 2/4] iio: sca3000: switch IRQ handling to devm helpers Harshit Mogalapalli
2026-01-31 16:30   ` Jonathan Cameron
2026-01-31 17:34     ` Harshit Mogalapalli
2026-01-31 19:21   ` David Lechner
2026-01-31 19:28     ` Harshit Mogalapalli
2026-01-30 21:43 ` [PATCH next 3/4] iio: sca3000: manage device registration with devm helper Harshit Mogalapalli
2026-01-31 16:32   ` Jonathan Cameron
2026-01-30 21:43 ` [PATCH next 4/4] iio: sca3000: stop interrupts via devm_add_action_or_reset() Harshit Mogalapalli
2026-01-31 16:39   ` Jonathan Cameron
2026-01-31 17:52     ` Harshit Mogalapalli [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=464ec1bb-858d-4ff5-8fa0-1c9af9b9945e@oracle.com \
    --to=harshit.m.mogalapalli@oracle.com \
    --cc=andrew.ijano@gmail.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=gustavobastos@usp.br \
    --cc=jic23@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®