public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v2] iio: gyro: adxrs290: Use guard(mutex) in lieu of manual lock+unlock
       [not found]   ` <20260424113901.0508dbc2@jic23-huawei>
@ 2026-04-27 22:04     ` Guilherme Dias
  2026-04-28  8:01       ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Guilherme Dias @ 2026-04-27 22:04 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Andy Shevchenko, nish.malpani25, lars, Michael.Hennerich,
	dlechner, nuno.sa, andy, João Paulo Menezes Linaris,
	linux-iio

Em sex., 24 de abr. de 2026 às 07:39, Jonathan Cameron
<jic23@kernel.org> escreveu:
>
> On Fri, 24 Apr 2026 12:24:07 +0300
> Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
>
> > On Thu, Apr 23, 2026 at 07:37:51PM -0300, Guilherme Dias wrote:
> > > Use guard(mutex) to automatically release the lock on scope exit,
> > > simplifying the error handling path and removing the need for
> > > explicit unlock and goto-based cleanup.
...
> > >     /* exercise a bulk data capture starting from reg DATAX0... */
> > >     ret = spi_write_then_read(st->spi, &tx, sizeof(tx), st->buffer.channels,
> > >                               sizeof(st->buffer.channels));
> > > -   if (ret < 0)
> > > -           goto out_unlock_notify;
> > > -
> > > -   iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
> > > +   if (ret >= 0)
> No to this as well. Keep the error out of line.  Which makes the use
> of guard() here tricky.  You could do a do { guard(); } while(0) loop so that
> you can use break with out it being odd looking.
>
> (I don't like breaks out of scoped_guard() because it's non obvious scoped
> guard is actually a loop.

Thanks for the suggestion — just to confirm I understood correctly, do
you mean something like this?

...
 do {

 guard(mutex)(&st->lock);

 /* exercise a bulk data capture starting from reg DATAX0... */
 ret = spi_write_then_read(st->spi, &tx, sizeof(tx), st->buffer.channels,
                          sizeof(st->buffer.channels));
 if (ret < 0)
            break;

 iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
                         pf->timestamp);
 } while (0);

 iio_trigger_notify_done(indio_dev->trig);
 return IRQ_HANDLED;
}

Keeping the error out of line again.

--
Kind regards,
Guilherme Dias

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] iio: gyro: adxrs290: Use guard(mutex) in lieu of manual lock+unlock
  2026-04-27 22:04     ` [PATCH v2] iio: gyro: adxrs290: Use guard(mutex) in lieu of manual lock+unlock Guilherme Dias
@ 2026-04-28  8:01       ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2026-04-28  8:01 UTC (permalink / raw)
  To: Guilherme Dias
  Cc: Jonathan Cameron, nish.malpani25, lars, Michael.Hennerich,
	dlechner, nuno.sa, andy, João Paulo Menezes Linaris,
	linux-iio

On Mon, Apr 27, 2026 at 07:04:23PM -0300, Guilherme Dias wrote:
> Em sex., 24 de abr. de 2026 às 07:39, Jonathan Cameron
> <jic23@kernel.org> escreveu:
> > On Fri, 24 Apr 2026 12:24:07 +0300
> > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > > On Thu, Apr 23, 2026 at 07:37:51PM -0300, Guilherme Dias wrote:

...

> > > >     /* exercise a bulk data capture starting from reg DATAX0... */
> > > >     ret = spi_write_then_read(st->spi, &tx, sizeof(tx), st->buffer.channels,
> > > >                               sizeof(st->buffer.channels));
> > > > -   if (ret < 0)
> > > > -           goto out_unlock_notify;

> > > > +   if (ret >= 0)
> > No to this as well. Keep the error out of line.  Which makes the use
> > of guard() here tricky.  You could do a do { guard(); } while(0) loop so that
> > you can use break with out it being odd looking.
> >
> > (I don't like breaks out of scoped_guard() because it's non obvious scoped
> > guard is actually a loop.
> 
> Thanks for the suggestion — just to confirm I understood correctly, do
> you mean something like this?

Yes, with proper indentation made.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-28  8:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260423223958.100487-1-guilhermeabreu200105@usp.br>
     [not found] ` <aes2tzgfXbuD6ccQ@ashevche-desk.local>
     [not found]   ` <20260424113901.0508dbc2@jic23-huawei>
2026-04-27 22:04     ` [PATCH v2] iio: gyro: adxrs290: Use guard(mutex) in lieu of manual lock+unlock Guilherme Dias
2026-04-28  8:01       ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox