Linux Kernel Mentees list
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: SeungJu Cheon <suunj1331@gmail.com>
Cc: linux-iio@vger.kernel.org, dlechner@baylibre.com,
	nuno.sa@analog.com, andy@kernel.org, apokusinski01@gmail.com,
	me@brighamcampbell.com, skhan@linuxfoundation.org,
	linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH 2/4] iio: pressure: mpl3115: clean up interrupt handling and locking
Date: Sat, 30 May 2026 16:23:35 +0100	[thread overview]
Message-ID: <20260530162335.048cfec4@jic23-huawei> (raw)
In-Reply-To: <20260530113938.171540-3-suunj1331@gmail.com>

On Sat, 30 May 2026 20:39:36 +0900
SeungJu Cheon <suunj1331@gmail.com> wrote:

> Return IRQ_NONE instead of IRQ_HANDLED when reading
> INT_SOURCE fails.

As in previous, wrap to 75 chars for commit messges.

> 
> On shared interrupt lines, returning IRQ_HANDLED after a
> failed register read may prevent other handlers from being
> invoked.

From what I recall that is simply not true.  Given interrupts might occur
at same moment, the shared interrupt code calls all handlers as it can't
tell if how many interrupt sources have signalled an interrupt.

Look more closely at what isn't invoked (hint it's about when things
go wrong!)

Also, doesn't look to me like this driver supports sharing of the interrupt
anyway.


> 
> Switch the trigger handler from explicit mutex_lock/unlock
> to scoped_guard() for consistency with the locking style
> used elsewhere in the driver.

I'm a little dubious about the value of scoped_guard() for such simple
cases but I guess it is harmless.  As Andy called out though, different
type of change, different patch.

Hmm. Actually do it by pushing the lock down into the function called
instead and there you can use a guard(). Has the added advantage of making
the exact scope of the locking visible next to the calls in it.
So put it in mpl3115_fill_trig_buffer().

> 
> Move mpl3115_config_interrupt() above the interrupt handler
> in preparation for the FIFO support added in a subsequent
> patch.

Separate patch as moving and doing other things just makes for harder
to review code.

> 
> No functional change intended.

Except for the one you call out above.

> 
> Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
> ---
>  drivers/iio/pressure/mpl3115.c | 59 +++++++++++++++++-----------------
>  1 file changed, 29 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
> index befb6d48efa9..52a3d0d59769 100644
> --- a/drivers/iio/pressure/mpl3115.c
> +++ b/drivers/iio/pressure/mpl3115.c
> @@ -308,9 +308,8 @@ static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
>  	u8 buffer[16] __aligned(8) = { };
>  	int ret;
>  
> -	mutex_lock(&data->lock);
> -	ret = mpl3115_fill_trig_buffer(indio_dev, buffer);
> -	mutex_unlock(&data->lock);
> +	scoped_guard(mutex, &data->lock)
> +		ret = mpl3115_fill_trig_buffer(indio_dev, buffer);
>  	if (ret)
>  		goto done;
>  
> @@ -322,6 +321,32 @@ static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
>  	return IRQ_HANDLED;
>  }
>  
> +static int mpl3115_config_interrupt(struct mpl3115_data *data,
> +				    u8 ctrl_reg1, u8 ctrl_reg4)
> +{
> +	int ret;
> +
> +	ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
> +					ctrl_reg1);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG4,
> +					ctrl_reg4);
> +	if (ret < 0)
> +		goto reg1_cleanup;
> +
> +	data->ctrl_reg1 = ctrl_reg1;
> +	data->ctrl_reg4 = ctrl_reg4;
> +
> +	return 0;
> +
> +reg1_cleanup:
> +	i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
> +				  data->ctrl_reg1);
> +	return ret;
> +}
> +
>  static const struct iio_event_spec mpl3115_temp_press_event[] = {
>  	{
>  		.type = IIO_EV_TYPE_THRESH,
> @@ -381,7 +406,7 @@ static irqreturn_t mpl3115_interrupt_handler(int irq, void *private)
>  
>  	ret = i2c_smbus_read_byte_data(data->client, MPL3115_INT_SOURCE);
>  	if (ret < 0)
> -		return IRQ_HANDLED;
> +		return IRQ_NONE;

So the fun of error handling in interrupt threads.  Arguably we have no idea
if it was our interrupt or not if this occurs - which I suspect is the motivation
of the author in returning IRQ_HANDLED here (and IRQ_NONE when we did read but there
were no interrupts).

I think IRQ_NONE still makes more sense because if we do have an intermittent fault
and the state is such that the interrupt will retrigger, then it doesn't matter if we
flag one spurious interrupt.


>  
>  	if (!(ret & (MPL3115_INT_SRC_TTH | MPL3115_INT_SRC_PTH |
>  		     MPL3115_INT_SRC_DRDY)))
> @@ -420,32 +445,6 @@ static irqreturn_t mpl3115_interrupt_handler(int irq, void *private)
>  	return IRQ_HANDLED;
>  }
>  
> -static int mpl3115_config_interrupt(struct mpl3115_data *data,
> -				    u8 ctrl_reg1, u8 ctrl_reg4)
> -{
> -	int ret;
> -
> -	ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
> -					ctrl_reg1);
> -	if (ret < 0)
> -		return ret;
> -
> -	ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG4,
> -					ctrl_reg4);
> -	if (ret < 0)
> -		goto reg1_cleanup;
> -
> -	data->ctrl_reg1 = ctrl_reg1;
> -	data->ctrl_reg4 = ctrl_reg4;
> -
> -	return 0;
> -
> -reg1_cleanup:
> -	i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
> -				  data->ctrl_reg1);
> -	return ret;
> -}
> -
>  static int mpl3115_set_trigger_state(struct iio_trigger *trig, bool state)
>  {
>  	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);


  parent reply	other threads:[~2026-05-30 15:23 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-30 11:39 [PATCH 0/4] iio: pressure: mpl3115: add hardware FIFO support SeungJu Cheon
2026-05-30 11:39 ` [PATCH 1/4] iio: pressure: mpl3115: convert probe to fully devm managed SeungJu Cheon
2026-05-30 12:12   ` Andy Shevchenko
2026-05-31 10:46     ` SeungJu Cheon
2026-05-30 15:10   ` Jonathan Cameron
2026-05-31 10:49     ` SeungJu Cheon
2026-05-31 14:29       ` Jonathan Cameron
2026-05-30 11:39 ` [PATCH 2/4] iio: pressure: mpl3115: clean up interrupt handling and locking SeungJu Cheon
2026-05-30 12:33   ` Andy Shevchenko
2026-05-31 10:55     ` SeungJu Cheon
2026-05-30 15:23   ` Jonathan Cameron [this message]
2026-05-31 10:59     ` SeungJu Cheon
2026-05-30 11:39 ` [PATCH 3/4] iio: pressure: mpl3115: generalize interrupt pin routing SeungJu Cheon
2026-05-30 12:39   ` Andy Shevchenko
2026-05-31 11:01     ` SeungJu Cheon
2026-05-30 15:32   ` Jonathan Cameron
2026-05-31 11:08     ` SeungJu Cheon
2026-05-30 11:39 ` [PATCH 4/4] iio: pressure: mpl3115: add hardware FIFO support SeungJu Cheon
2026-05-30 13:32   ` Andy Shevchenko
2026-05-30 15:43     ` Jonathan Cameron
2026-06-02 10:31       ` Andy Shevchenko
2026-05-31 11:15     ` SeungJu Cheon
2026-05-30 16:05   ` Jonathan Cameron
2026-05-31 12:38     ` SeungJu Cheon

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=20260530162335.048cfec4@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=apokusinski01@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=me@brighamcampbell.com \
    --cc=nuno.sa@analog.com \
    --cc=skhan@linuxfoundation.org \
    --cc=suunj1331@gmail.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