drivers/iio/dac/mcp47a1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
The MCP47A1 has 64 resistors but exposes 65 wiper positions. The valid
DAC codes are 0 through 64, and code 64 selects VREF.
The driver currently advertises 0 through 63 and uses 64 as the length
argument to in_range(), which also rejects 64. Therefore userspace
cannot select full-scale output.
Advertise code 64 and make validation cover all 65 codes. Keep 64 as
the scale denominator because the output voltage is VREF multiplied by
the code and divided by 64.
Fixes: 350d1fb9204b ("iio: dac: mcp47a1: add support for new device")
Signed-off-by: Tuna Kılıç <tuna@tunakilic.com>
---
drivers/iio/dac/mcp47a1.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/dac/mcp47a1.c b/drivers/iio/dac/mcp47a1.c
index 0bf994aa0e4..3ed306f3060 100644
--- a/drivers/iio/dac/mcp47a1.c
+++ b/drivers/iio/dac/mcp47a1.c
@@ -26,7 +26,7 @@ struct mcp47a1_data {
int vref_mV;
};
-static const int mcp47a1_raw_avail[] = { 0, 1, MCP47A1_MAX_STEPS - 1 };
+static const int mcp47a1_raw_avail[] = { 0, 1, MCP47A1_MAX_STEPS };
static const struct iio_chan_spec mcp47a1_channel = {
.type = IIO_VOLTAGE,
@@ -46,7 +46,7 @@ static int mcp47a1_write(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- if (!in_range(val, 0, MCP47A1_MAX_STEPS))
+ if (!in_range(val, 0, MCP47A1_MAX_STEPS + 1))
return -EINVAL;
return i2c_smbus_write_byte_data(data->client, MCP47A1_CMD_CODE,
--
2.55.0
Hi Tuna,
Thanks for the patch!
On Fri, 4 Sep 2026 12:25:17 +0000 (UTC)
Tuna Kılıç <tuna@tunakilic.com> wrote:
> The MCP47A1 has 64 resistors but exposes 65 wiper positions. The valid
> DAC codes are 0 through 64, and code 64 selects VREF.
>
> The driver currently advertises 0 through 63 and uses 64 as the length
> argument to in_range(), which also rejects 64. Therefore userspace
> cannot select full-scale output.
>
> Advertise code 64 and make validation cover all 65 codes. Keep 64 as
> the scale denominator because the output voltage is VREF multiplied by
> the code and divided by 64.
>
> Fixes: 350d1fb9204b ("iio: dac: mcp47a1: add support for new device")
> Signed-off-by: Tuna Kılıç <tuna@tunakilic.com>
> ---
This makes sense, I must've misread the datasheet...
Can I ask how this was found? Manual code analysis or AI?
--
Kind regards,
Joshua Crofts
On Fri, Sep 4, 2026 at 2:38 PM Joshua Crofts <joshua.crofts1@gmail.com> wrote: > Can I ask how this was found? Manual code analysis or AI? I noticed it while reviewing the driver's range handling and then compared it with the MCP47A1 datasheet. AI was used as an aid during the analysis, but I manually verified the datasheet values, in_range() semantics, and the final patch before sending it. I don't have MCP47A1 hardware available, so the testing was limited to build and static checks. Thanks, Tuna
On Fri, 4 Sep 2026 12:51:04 +0000 (UTC) Tuna Kılıç <tuna@tunakilic.com> wrote: > On Fri, Sep 4, 2026 at 2:38 PM Joshua Crofts <joshua.crofts1@gmail.com> wrote: > > Can I ask how this was found? Manual code analysis or AI? > > I noticed it while reviewing the driver's range handling and then > compared it with the MCP47A1 datasheet. AI was used as an aid during > the analysis, but I manually verified the datasheet values, in_range() > semantics, and the final patch before sending it. > If AI had anything much to do with generating the patch then a tag for Assisted-by: LLM is appropriate as part of the tags block. Same if the bug was found via LLM. The verification is good though. I'll wait for tags from Joshua on this once testing is done. Jonathan > I don't have MCP47A1 hardware available, so the testing was limited to > build and static checks. > > Thanks, > Tuna
> If AI had anything much to do with generating the patch then > a tag for Assisted-by: LLM is appropriate. AI was only used afterwards as a sanity check for the datasheet, in_range() semantics, and the final patch. The bug and fix came from manual review. Thanks, Tuna
On Sun, 6 Sep 2026 09:08:06 +0000 (UTC) Tuna Kılıç <tuna@tunakilic.com> wrote: > > If AI had anything much to do with generating the patch then > > a tag for Assisted-by: LLM is appropriate. > > AI was only used afterwards as a sanity check for the datasheet, > in_range() semantics, and the final patch. The bug and fix came from > manual review. Ah fair enough then to not add a tag. Thanks, Jonathan > > Thanks, > Tuna
On Sun, 6 Sep 2026 18:59:42 +0100 Jonathan Cameron <jic23@kernel.org> wrote: > On Sun, 6 Sep 2026 09:08:06 +0000 (UTC) > Tuna Kılıç <tuna@tunakilic.com> wrote: > > > > If AI had anything much to do with generating the patch then > > > a tag for Assisted-by: LLM is appropriate. > > > > AI was only used afterwards as a sanity check for the datasheet, > > in_range() semantics, and the final patch. The bug and fix came from > > manual review. > Ah fair enough then to not add a tag. > > Thanks, > > Jonathan > > > > > Thanks, > > Tuna > Hi all, sorry for the testing delay, did some light travelling this weekend and didn't have the hardware with me. Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com> Tested-by: Joshua Crofts <joshua.crofts1@gmail.com> -- Kind regards, Joshua Crofts
On Sun, 6 Sep 2026 21:44:20 +0200 Joshua Crofts <joshua.crofts1@gmail.com> wrote: > On Sun, 6 Sep 2026 18:59:42 +0100 > Jonathan Cameron <jic23@kernel.org> wrote: > > > On Sun, 6 Sep 2026 09:08:06 +0000 (UTC) > > Tuna Kılıç <tuna@tunakilic.com> wrote: > > > > > > If AI had anything much to do with generating the patch then > > > > a tag for Assisted-by: LLM is appropriate. > > > > > > AI was only used afterwards as a sanity check for the datasheet, > > > in_range() semantics, and the final patch. The bug and fix came from > > > manual review. > > Ah fair enough then to not add a tag. > > > > Thanks, > > > > Jonathan > > > > > > > > Thanks, > > > Tuna > > > > Hi all, > > sorry for the testing delay, did some light travelling this weekend > and didn't have the hardware with me. > > Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com> > Tested-by: Joshua Crofts <joshua.crofts1@gmail.com> No problem at all! Thanks for following up. Patch applied and marked for stable. Thanks, Jonathan >
© 2016 - 2026 Red Hat, Inc.