public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Antoni Pokusinski <apokusinski01@gmail.com>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	andy@kernel.org, marcelo.schmitt1@gmail.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: mpl3115: add threshold events support
Date: Thu, 30 Oct 2025 11:18:09 +0200	[thread overview]
Message-ID: <aQMtUUp_QoR4l3nd@smile.fi.intel.com> (raw)
In-Reply-To: <20251029224605.3ixkvmmkm36iwh22@antoni-VivoBook-ASUSLaptop-X512FAY-K512FA>

On Wed, Oct 29, 2025 at 11:46:05PM +0100, Antoni Pokusinski wrote:
> On Wed, Oct 29, 2025 at 10:24:49AM +0200, Andy Shevchenko wrote:
> > On Tue, Oct 28, 2025 at 10:33:52PM +0100, Antoni Pokusinski wrote:

Please, remove context you are agree with!
Otherwise raise your point(s).

...


> > > -	u8 ctrl_reg1 = data->ctrl_reg1;
> > > -	u8 ctrl_reg4 = data->ctrl_reg4;
> > > +	u8 ctrl_reg1, ctrl_reg4;
> > 
> > > +	guard(mutex)(&data->lock);
> > 
> > Why this is moved? Before the access to the data->ctrl* was done without
> > locking. Is it an existing bug?
> > 
> Since this patchset adds `write_event_config()` in which CTRL_REG1.ACTIVE
> and CTRL_REG4 are modified, the lock now needs to guard the read of
> data->ctrl_regX as well. Otherwise, we could have e.g. 2 concurrent
> threads executing `set_trigger_state()` and `write_event_config()` that
> would read data->ctrl_regX at the same time and then one would overwrite
> the other's values in `config_interrupt()`.
> 
> In the current driver I don't think there is any bug in here. The only
> place (except probe) where the data->ctrl_regX is modified is
> `config_interrupt()`, called from `set_trigger_state()`. If we had
> concurrent calls to this function, then the final values of CTRL_REG1
> and CTRL_REG4 would simply depend on which thread is scheduled as the last one.
> With the `guard(mutex)` before accessing data->ctrl_reg1, the situation
> would be exactly the same.

I see, can you summarize this in the commit message as well?
And/or in the code near to the lock description.

> > > +	ctrl_reg1 = data->ctrl_reg1;
> > > +	ctrl_reg4 = data->ctrl_reg4;
> > >  
> > >  	if (state) {
> > >  		ctrl_reg1 |= MPL3115_CTRL1_ACTIVE;
> > >  		ctrl_reg4 |= MPL3115_CTRL4_INT_EN_DRDY;
> > >  	} else {
> > > -		ctrl_reg1 &= ~MPL3115_CTRL1_ACTIVE;
> > >  		ctrl_reg4 &= ~MPL3115_CTRL4_INT_EN_DRDY;
> > > -	}
> > >  
> > > -	guard(mutex)(&data->lock);
> > > +		if (!ctrl_reg4)
> > > +			ctrl_reg1 &= ~MPL3115_CTRL1_ACTIVE;
> > > +	}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-10-30  9:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28 21:33 [PATCH 0/2] iio: mpl3115: support for events Antoni Pokusinski
2025-10-28 21:33 ` [PATCH 1/2] iio: mpl3115: add ctrl_reg4 to mpl3115_data Antoni Pokusinski
2025-10-29 17:20   ` Marcelo Schmitt
2025-10-28 21:33 ` [PATCH 2/2] iio: mpl3115: add threshold events support Antoni Pokusinski
2025-10-29  8:24   ` Andy Shevchenko
2025-10-29 22:46     ` Antoni Pokusinski
2025-10-30  9:18       ` Andy Shevchenko [this message]
2025-10-29 17:13   ` Marcelo Schmitt

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=aQMtUUp_QoR4l3nd@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=apokusinski01@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --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