From: Joshua Crofts <joshua.crofts1@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: sashiko-bot@kernel.org, sashiko-reviews@lists.linux.dev,
devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org,
linux-iio@vger.kernel.org, andy@kernel.org, nuno.sa@analog.com,
dlechner@baylibre.com
Subject: Re: [PATCH v2 2/2] iio: dac: mcp47a1: add support for new device
Date: Sat, 1 Aug 2026 07:28:50 +0200 [thread overview]
Message-ID: <20260801072850.6f5d255e@systembl0wer> (raw)
In-Reply-To: <20260801033013.19ef2b2f@jic23-huawei>
On Sat, 1 Aug 2026 03:30:13 +0100
Jonathan Cameron <jic23@kernel.org> wrote:
> On Tue, 28 Jul 2026 15:15:59 +0200
> Joshua Crofts <joshua.crofts1@gmail.com> wrote:
>
> > On Mon, 27 Jul 2026 18:42:26 +0000
> > sashiko-bot@kernel.org wrote:
> >
> > > Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> > > - [Medium] Potential off-by-one in DAC scale calculation denominator.
> > > --
> >
> > Responding to Sashiko's comment.
> >
> > > --- Patch [2]: [PATCH v2 2/2] iio: dac: mcp47a1: add support for new device ---
> > > commit 38bec2fbb020c3f749c52a26e5cc3e78e72eeaf5
> > > Author: Joshua Crofts <joshua.crofts1@gmail.com>
> > >
> > > iio: dac: mcp47a1: add support for new device
> > >
> > > The Microchip MCP47A1 is a 6-bit volatile Digital-to-Analog converter
> > > which communicates via I2C.
> > >
> > > > diff --git a/drivers/iio/dac/mcp47a1.c b/drivers/iio/dac/mcp47a1.c
> > > > new file mode 100644
> > > > index 0000000000000..140e93ff2ba01
> > > > --- /dev/null
> > > > +++ b/drivers/iio/dac/mcp47a1.c
> > > [ ... ]
> > > > +static int mcp47a1_read(struct iio_dev *indio_dev,
> > > > + struct iio_chan_spec const *chan,
> > > > + int *val, int *val2, long mask)
> > > > +{
> > > > + struct mcp47a1_data *data = iio_priv(indio_dev);
> > > > + int ret;
> > > > +
> > > > + switch (mask) {
> > > [ ... ]
> > > > + case IIO_CHAN_INFO_SCALE:
> > > > + *val = data->vref_mV;
> > > > + *val2 = MCP47A1_MAX_STEP;
> > >
> > > [Severity: Medium]
> > > Does this code use the correct denominator for the scale calculation?
> > >
> > > Since this is a 6-bit DAC, shouldn't the scale denominator be 64 (2^6)
> > > instead of the maximum step value of 63? Using MCP47A1_MAX_STEP (63) here
> > > introduces an off-by-one error that could cause userspace to calculate
> > > output voltages with a ~1.5% LSB scaling error when reading the sysfs
> > > attribute.
> >
> > Yes, the max amount of steps is 64, which should be passed here. I'll
> > add a separate macro for this in v3.
> I'd just use + 1 at this location given the clear relationship between
> the maximum value that can be taken and the number of steps.
Good to know, for some reason I thought that this type of stuff was
discouraged (MACRO_NAME + x would seem messy in most cases).
--
Kind regards,
Joshua Crofts
next prev parent reply other threads:[~2026-08-01 5:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 18:31 [PATCH v2 0/2] iio: dac: mcp47a1: add support for new device Joshua Crofts
2026-07-27 18:31 ` [PATCH v2 1/2] dt-bindings: iio: dac: add support for mcp47a1 Joshua Crofts
2026-07-27 18:31 ` [PATCH v2 2/2] iio: dac: mcp47a1: add support for new device Joshua Crofts
[not found] ` <20260727184226.DFC1E1F000E9@smtp.kernel.org>
2026-07-28 13:15 ` Joshua Crofts
2026-08-01 2:30 ` Jonathan Cameron
2026-08-01 5:28 ` Joshua Crofts [this message]
2026-08-01 2:31 ` Jonathan Cameron
2026-08-01 15:02 ` David Lechner
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=20260801072850.6f5d255e@systembl0wer \
--to=joshua.crofts1@gmail.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=sashiko-bot@kernel.org \
--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