Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Svyatoslav Ryhel" <clamor95@gmail.com>,
	"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>,
	"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: Sat, 28 Nov 2026 20:53:00 +0000	[thread overview]
Message-ID: <20261128205300.5361ccb0@jic23-hlaptop> (raw)
In-Reply-To: <awSaBqLabqZ68ak9@ashevche-desk.local>


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

So a mixed reply.  In majority of cases I'd agree with Andy that the documentation
value would make it a good idea, but let us look at the code in question. 

        ret = regmap_read_poll_timeout(map, MAX8907_REG_TSC_STA_INT, value,
                                        !(value & MAX8907_MASK_NREF_OK),
                                       10, 1 * USEC_PER_MSEC);

So the reason I don't like it here is that 10 and the result that we represent
them in different ways.  So I do slightly prefer the 1000 here as then we can
see immediately that we have a reasonable ratio of poll to timeout.

These are subtle so there is often no perfect answer particularly when
like this we have timeout and timing related functions with no great consistency
on timebase.

It could be made explicit.

	timeout_usecs = 1 * USEC_PER_MSEC;

        ret = regmap_read_poll_timeout(map, MAX8907_REG_TSC_STA_INT, value,
                                        !(value & MAX8907_MASK_NREF_OK),
                                       timeout_usecs / 100, timeout_usecs);
Which I think is the clearest of all options for this - but at cost of
a local variable - hence not perfect either!

Jonathan

  reply	other threads:[~2026-11-28 20:53 UTC|newest]

Thread overview: 13+ 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
2026-11-28 20:53         ` Jonathan Cameron [this message]
2026-11-29 16:08         ` Svyatoslav Ryhel
2026-11-29 19:21           ` Jonathan Cameron
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=20261128205300.5361ccb0@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=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=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