Re: [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell

From: Svyatoslav Ryhel

Date: Sun Nov 29 2026 - 11:09:07 EST


пн, 23 лист. 2026 р. о 21:54 Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> пише:
>
> On Mon, Nov 23, 2026 at 09:24:30PM +0200, Svyatoslav Ryhel wrote:
> > пн, 23 лист. 2026 р. о 21:01 Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> пише:
> > > 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;
> >

So if you want this, then it is better to restore driver data with
regmap pointer in it. Would be easier to read without those **, it
would follow established patterns and if extension is needed, driver
data is ready.

> > 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.
>

So wrap everything 80 chars strictly? Just asking to be sure.

> > > 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 :-)
>

And use struct regmap *map ?

> ...
>
> > > 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.
>

And may you explicitly say how you want it to look?

> ...
>
> > I would like to hear what Jonathan has to say.
>
> OK.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>