From: Conor Dooley <conor@kernel.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: sashiko-reviews@lists.linux.dev, linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v3] hwmon: add a driver for the temp/voltage sensor on PolarFire SoC
Date: Thu, 11 Jun 2026 17:57:49 +0100 [thread overview]
Message-ID: <20260611-strained-cadet-7ea5fd2cba19@spud> (raw)
In-Reply-To: <4a5f47d6-90ac-4365-b4ae-02d4ca4d31d4@roeck-us.net>
[-- Attachment #1: Type: text/plain, Size: 3688 bytes --]
On Thu, Jun 11, 2026 at 09:41:49AM -0700, Guenter Roeck wrote:
> On Thu, Jun 11, 2026 at 05:21:41PM +0100, Conor Dooley wrote:
> > On Thu, Jun 11, 2026 at 03:13:16PM +0000, sashiko-bot@kernel.org wrote:
> > > Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> > > - [Medium] Negative values written to `update_interval` are incorrectly clamped to the maximum interval instead of returning an error or clamping to 0.
> > > - [Medium] Reading `update_interval` inconsistently under-reports the configured value due to integer division truncation.
> > > - [Medium] Hardware sensors are enabled in `probe` but are not disabled on probe failure or driver unbind.
> > > --
> > >
> > > commit 91a403f5c5eef9fbcfcab3857179dc2f03ad3c89
> > > Author: Lars Randers <lranders@mail.dk>
> > >
> > > hwmon: add a driver for the temp/voltage sensor on PolarFire SoC
> > >
> > > Add a driver for the temperature and voltage sensors on PolarFire SoC.
> > > The temperature reports how hot the die is, and the voltages are the
> > > SoC's 1.05, 1.8 and 2.5 volt rails respectively.
> > >
> > > > diff --git a/drivers/hwmon/tvs-mpfs.c b/drivers/hwmon/tvs-mpfs.c
> > > > new file mode 100644
> > > > index 0000000000000..48de8d98b3444
> > > > --- /dev/null
> > > > +++ b/drivers/hwmon/tvs-mpfs.c
> > >
> > > [ ... ]
> > >
> > > > +static int mpfs_tvs_interval_read(struct mpfs_tvs *data, u32 attr, long *val)
> > > > +{
> > > > + u32 tmp;
> > > > +
> > > > + if (attr != hwmon_chip_update_interval)
> > > > + return -EOPNOTSUPP;
> > > > +
> > > > + regmap_read(data->regmap, MPFS_TVS_CTRL, &tmp);
> > > > + *val = FIELD_GET(MPFS_TVS_INTERVAL_MASK, tmp);
> > > > + *val *= MPFS_TVS_INTERVAL_SCALE;
> > > > + *val /= 1000;
> > >
> > > [Severity: Medium]
> > > Will this return an incorrectly truncated value for certain intervals?
> > >
> > > Since integer division is used both here and in mpfs_tvs_interval_write(),
> > > the truncation can cause the readback value to be lower than what was written.
> > > For example, writing 7 ms calculates `(7 * 1000) / 32 = 218`. Reading it back
> > > computes `(218 * 32) / 1000 = 6` ms.
> > >
> > > Should DIV_ROUND_CLOSEST be used for these conversions to ensure the value
> > > survives the round trip?
> >
> > Hmm, this is actually a good point that I overlooked.
> > What is the desired rounding behaviour here?
> > IOW, should asking for 7 ms produce the closest interval less than 7 ms or
> > the closest interval greater than 7 ms?
> >
> > A consistent rounding is better than rounding to the closest IMO, if both
> > update_interval and update_interval_us are going to be supported
> >
>
> Not sure what you mean with "consistent rounding". Effectively the current
What I meant was that it would round to an interval that would either be
at least (always down) or at most (always up) as frequently as requested.
If, for example, the interval was set to 7400 or 7600 us via
update_interval_us, and then read back from update_interval, that the
rounding used for that would do the same thing as operating entirely via
update_interval and always display an interval that was at least as or
as most as frequent as the configured value.
Rounding closest would of course produce different results for 7400 and
7600, with one being more frequent and one less frequent than reality.
> code is rounding down. I personally like using DIV_ROUND_CLOSEST() for both
> read and write conversions because it gives the most accurate result. So
> (7 * 1000) / 32 = 218.75 would result in 219 and (219 * 32) / 1000 = 7.008
> would result in 7.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-06-11 16:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 15:00 [PATCH v3] hwmon: add a driver for the temp/voltage sensor on PolarFire SoC Conor Dooley
2026-06-11 15:13 ` sashiko-bot
2026-06-11 16:21 ` Conor Dooley
2026-06-11 16:41 ` Guenter Roeck
2026-06-11 16:57 ` Conor Dooley [this message]
2026-06-11 17:44 ` Guenter Roeck
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=20260611-strained-cadet-7ea5fd2cba19@spud \
--to=conor@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=sashiko-reviews@lists.linux.dev \
/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