mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy@kernel.org>
To: Lothar Rubusch <l.rubusch@gmail.com>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	corbet@lwn.net, lucas.p.stankus@gmail.com, lars@metafoo.de,
	Michael.Hennerich@analog.com, linux-iio@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 09/12] iio: accel: adxl313: add activity sensing
Date: Wed, 21 May 2025 12:58:45 +0300	[thread overview]
Message-ID: <aC2j1U11BqkDn2II@smile.fi.intel.com> (raw)
In-Reply-To: <CAFXKEHavquk_oyhMpkawkKUwnfNA_eFWH5XYFsZQkM1_-Rh6Vg@mail.gmail.com>

On Tue, May 20, 2025 at 10:25:03PM +0200, Lothar Rubusch wrote:
> > On Sun, May 18, 2025 at 11:13:18AM +0000, Lothar Rubusch wrote:

...

> > > +static int adxl313_set_act_inact_en(struct adxl313_data *data,
> > > +                               enum adxl313_activity_type type,
> > > +                               bool cmd_en)
> > > +{
> > > +   unsigned int axis_ctrl = 0;
> > > +   unsigned int threshold;
> > > +   bool en;
> > > +   int ret;
> > > +
> > > +   if (type == ADXL313_ACTIVITY)
> > > +           axis_ctrl = ADXL313_ACT_XYZ_EN;
> > > +
> > > +   ret = regmap_update_bits(data->regmap,
> > > +                            ADXL313_REG_ACT_INACT_CTL,
> > > +                            axis_ctrl,
> > > +                            cmd_en ? 0xff : 0x00);
> > > +   if (ret)
> > > +           return ret;
> > > +
> > > +   ret = regmap_read(data->regmap, adxl313_act_thresh_reg[type], &threshold);
> > > +   if (ret)
> > > +           return ret;
> >
> > > +   en = false;
> >
> > Instead...
> >
> > > +   if (type == ADXL313_ACTIVITY)
> > > +           en = cmd_en && threshold;
> >
> >       else
> >               en = false;
> >
> > > +   return regmap_update_bits(data->regmap, ADXL313_REG_INT_ENABLE,
> > > +                             adxl313_act_int_reg[type],
> > > +                             en ? adxl313_act_int_reg[type] : 0);
> > > +}
> 
> The above is a good example for the following. From time to time, I face
> the situation in a function where I'd like to end up with something like
> 
>     if (foo = A) {
>         var = thenDoA();
>     } else {
>         var = thenDoB();
>     }
>     doSomething(var);
> 
> In a first patch I'll introduce only the following and remark in the
> commit message, that this will be extended. Since smatch/sparse tool
> will complain, I'll need to fiddle around with initializations
> (becoming obsolete in the end), e.g. I'll end up with something like
> this in a first patch A:
> 
>     var = nonsense;
>     if (foo = A) {
>         var = thenDoA();
>     }
>     doSomething(var);
> 
> This is the case for switch(type) case IIO_...MAG: as only type (for
> now). This is the case for this is_act_inact_enabled(),
> set_act_inact(), etc.
> 
> I assume it's better to simplify each commit individually and don't
> leave the "churn" around which might make sense in combination with a
> follow patch? Is this a general approach I should follow?

I believe so.

> Or, can it be legitimate to just split an if/else and add if-clause in
> a patch A and the else clause in the other patch B, since both are
> probably actually not complex. Such that patch A for itself looks a
> bit odd, but will make sense together with patch B?

Yes, but just make sure the each of the patches (after being applied) give the
plausible result.

...

> > > +static int adxl313_read_event_config(struct iio_dev *indio_dev,
> > > +                                const struct iio_chan_spec *chan,
> > > +                                enum iio_event_type type,
> > > +                                enum iio_event_direction dir)
> > > +{
> > > +   struct adxl313_data *data = iio_priv(indio_dev);
> >
> > > +   bool int_en;
> >
> > Why? You return the int here... I would expect rather to see unsigned int...
> >
> > > +   int ret;
> > > +
> > > +   switch (type) {
> > > +   case IIO_EV_TYPE_MAG:
> > > +           switch (dir) {
> > > +           case IIO_EV_DIR_RISING:
> > > +                   ret = adxl313_is_act_inact_en(data,
> > > +                                                 ADXL313_ACTIVITY,
> > > +                                                 &int_en);
> > > +                   if (ret)
> > > +                           return ret;
> > > +                   return int_en;
> >
> > ...or even simply
> >
> >                       return adx1313...(...);
> >
> > > +           default:
> > > +                   return -EINVAL;
> > > +           }
> > > +   default:
> > > +           return -EINVAL;
> > > +   }
> > > +}
> 
> This one here is interesting, to my understanding I followed here e.g.
> the approach of the ADXL380 which is supposed to be a quite recent
> driver [the _read/write_event_config() there.]

> Now, your remark made me think: I'm unsure, can I actually I implement
> the following approach here?
> - return >0 : true

=1, but yes. We have plenty of functions like this in the kernel.

> - return =0 : false
> - return <0 : error
> 
> It seems to work (unsure about the  error cases, though),
> but much cleaner and simpler! I'll send that in v2,
> pls let me know if I missunderstood you.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-05-21  9:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-20 20:25 Lothar Rubusch
2025-05-21  9:58 ` Andy Shevchenko [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-05-18 11:13 [PATCH v1 00/12] iio: accel: adxl313: add power-save on activity/inactivity Lothar Rubusch
2025-05-18 11:13 ` [PATCH v1 09/12] iio: accel: adxl313: add activity sensing Lothar Rubusch
2025-05-19 12:15   ` Andy Shevchenko

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=aC2j1U11BqkDn2II@smile.fi.intel.com \
    --to=andy@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=corbet@lwn.net \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=l.rubusch@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.p.stankus@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

all inboxes | Powered by JetHome®