mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Nuno Sá" <nuno.sa@analog.com>
Cc: Jinseob Kim <kimjinseob88@gmail.com>,
	dlechner@baylibre.com, andy@kernel.org,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: buffer: serialize buffer teardown with mode claims
Date: Fri, 25 Sep 2026 03:16:29 +0100	[thread overview]
Message-ID: <20260925031629.197e233c@jic23-hlaptop> (raw)
In-Reply-To: <arTeK0QadzWkI6jH@nsa>

On Thu, 24 Sep 2026 09:24:33 +0100
Nuno Sá <nuno.sa@analog.com> wrote:

> On Mon, Sep 21, 2026 at 03:24:21PM +0900, Jinseob Kim wrote:
> > Buffer-mode claims hold mlock to guarantee that the device remains in
> > buffer mode until the claim is released. Normal buffer updates take
> > info_exist_lock followed by mlock in iio_update_buffers().
> > 
> > However, iio_device_unregister() disables and deactivates all buffers
> > without taking mlock. This can invalidate buffer state, including
> > active_scan_mask, while a buffer-mode claim is held.
> > 
> > Take mlock in iio_disable_all_buffers() so that unregister honors the
> > mode-claim lifetime guarantee. The info_exist_lock -> mlock ordering
> > matches iio_update_buffers().
> > 
> > Fixes: 0a8565425afd ("iio: core: introduce iio_device_{claim|release}_buffer_mode() APIs")
> > Suggested-by: Jonathan Cameron <jic23@kernel.org>
> > Signed-off-by: Jinseob Kim <kimjinseob88@gmail.com>
> > ---  
> 
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Applied to the fixes-togreg branch of iio.git and marked for
stable inclusion. It should be safe enough but I do want to get
some testing on this. Crossed fingers!

Thanks,

Jonathan

> 
> >  drivers/iio/industrialio-buffer.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> > index 2c9ec93dff47..d60bad5492e7 100644
> > --- a/drivers/iio/industrialio-buffer.c
> > +++ b/drivers/iio/industrialio-buffer.c
> > @@ -1377,6 +1377,10 @@ EXPORT_SYMBOL_GPL(iio_update_buffers);
> >  
> >  void iio_disable_all_buffers(struct iio_dev *indio_dev)
> >  {
> > +	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> > +
> > +	guard(mutex)(&iio_dev_opaque->mlock);
> > +
> >  	iio_disable_buffers(indio_dev);
> >  	iio_buffer_deactivate_all(indio_dev);
> >  }
> > 
> > base-commit: dceba8e581e3e8f475da0efbd7a73f3d9524ddd2
> > -- 
> > 2.43.0
> >   


      reply	other threads:[~2026-09-25  2:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21  6:24 Jinseob Kim
2026-09-23  7:38 ` Joshua Crofts
2026-09-24  8:24 ` Nuno Sá
2026-09-25  2:16   ` Jonathan Cameron [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=20260925031629.197e233c@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=kimjinseob88@gmail.com \
    --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®