mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	jean-baptiste.maneyrol@tdk.com,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Julia Lawall" <Julia.Lawall@inria.fr>
Subject: Re: [PATCH v5 2/3] iio: imu: inv_icm42600: add WoM support
Date: Sat, 28 Jun 2025 16:40:54 +0100	[thread overview]
Message-ID: <20250628164054.54ae2e7a@jic23-huawei> (raw)
In-Reply-To: <dcf86acc-567e-48e3-ad15-fd9522b46180@sabinyo.mountain>

On Thu, 26 Jun 2025 14:48:10 -0500
Dan Carpenter <dan.carpenter@linaro.org> wrote:

> On Thu, Jun 26, 2025 at 07:53:23PM +0100, Jonathan Cameron wrote:
> > > > +static int inv_icm42600_accel_disable_wom(struct iio_dev *indio_dev)
> > > > +{
> > > > +       struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
> > > > +       struct device *pdev = regmap_get_device(st->map);
> > > > +       struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
> > > > +       unsigned int sleep_ms = 0;
> > > > +       int ret;
> > > > +
> > > > +       scoped_guard(mutex, &st->lock) {
> > > > +               /*
> > > > +                * Consider that turning off WoM is always working to avoid
> > > > +                * blocking the chip in on mode and prevent going back to sleep.
> > > > +                * If there is an error, the chip will anyway go back to sleep
> > > > +                * and the feature will not work anymore.
> > > > +                */
> > > > +               st->apex.wom.enable = false;
> > > > +               st->apex.on--;
> > > > +               ret = inv_icm42600_disable_wom(st);
> > > > +               if (ret)
> > > > +                       break;    
> > > 
> > > The fact that scoped_guard() uses a for loop is an implementation
> > > detail so using break here makes this look like improper C code. I
> > > think this would be better to split out the protected section to a
> > > separate function and just use the regular guard() macro.  
> > 
> > Good catch.  This feels like something we should have some static analysis
> > around as we definitely don't want code assuming that implementation.
> > 
> > +CC Dan / Julia to see if they agree.
> >   
> 
> I feel like the scoped_guard() macro is so complicated because they
> wanted break statements to work as expected...  (As opposed to how I write
> half my loop macros using nested for loops so that when I break it only
> breaks from the inner loop and corrupts memory).

Was a while back but don't remember that coming up as a reason.
I thought the for loop construct was just a way to define the scope in
a place where the following or preceding code couldn't influence what was
instantiated.

Anyhow I think breaks in a scoped_guard() is a horrible pattern based on hidden
implementation details so I'm keen to avoid it at least in IIO. 
Maybe this will become common enough that I'll revisit that view in a year
or two. Factoring out the code as a function seems the right answer in this
case.

Never mind on checking for it generally if we think it might be something
that was intended as a feature not a bug.

Thanks

Jonathan

> 
> regards,
> dan carpenter
> 


  parent reply	other threads:[~2025-06-28 15:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-23 12:55 [PATCH v5 0/3] Add support for WoM (Wake-on-Motion) feature Jean-Baptiste Maneyrol via B4 Relay
2025-06-23 12:55 ` [PATCH v5 1/3] iio: imu: inv_icm42600: move structure DMA buffers at the end Jean-Baptiste Maneyrol via B4 Relay
2025-06-23 22:13   ` David Lechner
2025-06-24  8:43     ` Jean-Baptiste Maneyrol
2025-06-26 18:48       ` Jonathan Cameron
2025-06-27 15:27         ` Jean-Baptiste Maneyrol
2025-06-27 17:19           ` David Lechner
2025-06-28 15:35             ` Jonathan Cameron
2025-06-23 12:55 ` [PATCH v5 2/3] iio: imu: inv_icm42600: add WoM support Jean-Baptiste Maneyrol via B4 Relay
2025-06-23 22:44   ` David Lechner
2025-06-26 18:53     ` Jonathan Cameron
2025-06-26 19:48       ` Dan Carpenter
2025-06-26 20:41         ` Julia Lawall
2025-06-27 15:32           ` Jean-Baptiste Maneyrol
2025-06-28 15:40         ` Jonathan Cameron [this message]
2025-06-23 12:55 ` [PATCH v5 3/3] iio: imu: inv_icm42600: add wakeup functionality for Wake-on-Motion Jean-Baptiste Maneyrol via B4 Relay

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=20250628164054.54ae2e7a@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Julia.Lawall@inria.fr \
    --cc=andy@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=dlechner@baylibre.com \
    --cc=jean-baptiste.maneyrol@tdk.com \
    --cc=lars@metafoo.de \
    --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®