Devicetree
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Svyatoslav Ryhel <clamor95@gmail.com>
Cc: "Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>, "Lee Jones" <lee@kernel.org>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-iio@vger.kernel.org, mfd@lists.linux.dev
Subject: Re: [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell
Date: Mon, 23 Nov 2026 21:54:46 +0200	[thread overview]
Message-ID: <awSaBqLabqZ68ak9@ashevche-desk.local> (raw)
In-Reply-To: <CAPVz0n2yBtFh-TJ13cH8WXtiyzR3tOrbhACyq8MThi_6+7DOYg@mail.gmail.com>

On Mon, Nov 23, 2026 at 09:24:30PM +0200, Svyatoslav Ryhel wrote:
> пн, 23 лист. 2026 р. о 21:01 Andy Shevchenko <andriy.shevchenko@intel.com> пише:
> > On Mon, Nov 23, 2026 at 05:07:24PM +0200, Svyatoslav Ryhel wrote:

...

> > > +#define MAX8907_CHAN(_type, _idname, _datasheet_name) {              \
> > > +     .type = (_type),                                        \
> > > +     .address = MAX8907_REG_##_idname##_MSB |                \
> > > +                MAX8907_REG_##_idname##_MEASURE << 8,        \
> > > +     .indexed = 1,                                           \
> > > +     .channel = (_idname),                                   \
> > > +     .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |          \
> > > +                           BIT(IIO_CHAN_INFO_SCALE),         \
> > > +     .scan_index = (_idname),                                \
> >
> > Using () means that you expect an expression as a possible input. In such
> > a case the macro is buggy as it will evaluate it twice for _idname. The
> > simple solution is to drop these parentheses and expect that this macro
> > won't ever be used with the expressions in the parameters.

> You have a point but current state should not cause issues as well.

I know, but I saw Sashiko's complain somewhere else on a similar situation.
It might or might not complain, better to be prepared.

> > > +     .scan_type = {                                          \
> > > +             .format = IIO_SCAN_FORMAT_UNSIGNED_INT,         \
> > > +             .realbits = 12,                                 \
> > > +             .storagebits = 16,                              \
> > > +             .endianness = IIO_CPU,                          \
> > > +     },                                                      \
> > > +     .datasheet_name = (_datasheet_name),                    \
> > > +}

...

> > > +     struct regmap **regmap = iio_priv(indio_dev);
> >
> > Then logically better to go further and have
> >
> >         struct regmap *map = *regmap;
> 
> This is matter of taste, I was inspired by MAX77541 ADC which uses
> exactly this approach.

Not really, however it's very unlikely to happen IRL. When you dereference
something the compiler is in its right to do it as many times as you used in
the code. Hence theoretically (in this driver) somebody might replace the
pointer and two consequent regmap calls will get different regmap.

...

> > > +             ret = regmap_bulk_read(*regmap, MAX8907_TO_REG(chan->address), &data, sizeof(data));
> >
> > This is a bit too long.
> 
> 101 char, yeah 1 char too long, though maybe it is not wort resending
> for a single char too long?

IIO is tending to follow documentation in majority of the drivers and cases
which is 80 limit.

> >                 ret = regmap_bulk_read(map, MAX8907_TO_REG(chan->address),
> >                                        &data, sizeof(data));

...

> > > +static int max8907_adc_init(struct regmap *regmap)
> >
> > Why not name it 'map'?
> 
> Because regmap is more explicit and is used consistently across the driver.

And messes with the data type name :-)

...

> >         ret = regmap_update_bits(map, MAX8907_REG_TSC_CNFG1, GENMASK(1, 0), BIT(1));
> 
> which map? bitmap? statemap? or maybe geographical map?

Read the name of the call. This is really silly question here.

> > > +     if (ret)
> > > +             return ret;

...

> > > +     /* Check for internal reference IRQ */
> >
> > Please, make style of one-line comments consistent ("all or none" are with or
> > without period, same for the first letter — capital or small).
> 
> First comment has 2 sentences, that is why it has periods. Second only
> one, so it does not need period.  "same for the first letter — capital
> or small" - have you even checked the patch?

Then make the style equal. Two sentences can be written differently.

And please, stop being rude. Yes, I read the patch, The second part is
unrelated, I am sorry for mentioning it.

...

> > > +     ret = regmap_read_poll_timeout(regmap, MAX8907_REG_TSC_STA_INT, value,
> > > +                                    !(value & MAX8907_MASK_NREF_OK), 10, 1000);
> >
> >         ret = regmap_read_poll_timeout(map, MAX8907_REG_TSC_STA_INT, value,
> >                                        !(value & MAX8907_MASK_NREF_OK),
> >                                        10, 1 * USEC_PER_MSEC);
> >
> 
> hmm, replace 1000 (4 chars, pretty readable) with USEC_PER_MSEC (12
> chars and twice wrapped line and needs tinkering or looking into
> units.h), I don't think so.

Because the point is missed? We have tons of much longer multipliers that kill
two birds with one stone:
- avoiding possible typos when many 0:s are in them (one can be missed or too many)
- hinting reader of the units of the used values without even looking into the docs
- (and reading 1...MSEC is quite natural, without counting 0:s and thinking how
   many of them and what 1000 microseconds, after spending time on the
   documentation, means in practice)

Please, use multipliers where it's makes code better to understand for
unprepared reader.

...

> I would like to hear what Jonathan has to say.

OK.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-11-23 19:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 15:07 [PATCH v3 0/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 1/4] regulator: dt-bindings: maxim,max8907: Document io-channel-cells property Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 2/4] mfd: max8907: Add ADC client support Svyatoslav Ryhel
2026-11-23 18:54   ` Andy Shevchenko
2026-11-23 19:10     ` Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
2026-11-23 19:01   ` Andy Shevchenko
2026-11-23 19:24     ` Svyatoslav Ryhel
2026-11-23 19:54       ` Andy Shevchenko [this message]
2026-11-23 15:07 ` [PATCH v3 4/4] mfd: max8907: Add " Svyatoslav Ryhel

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=awSaBqLabqZ68ak9@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=broonie@kernel.org \
    --cc=clamor95@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfd@lists.linux.dev \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /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