Skip to contentSkip to conversation

RESEND [PATCH v1] iio: potentiometer: mcp4131: fix double application of wiper shift

PATCH Lukas Schmid 2 participants 4 messages Feb 2 IIO

lore
Share & tools
lore
#0 lore raw

The MCP4131 wiper address is shifted twice when preparing the SPI command in mcp4131_write_raw().

The address is already shifted when assigned to the local variable "address", but is then shifted again when written to data->buf[0]. This results in an incorrect command being sent to the device and breaks wiper writes to the second channel.

Remove the second shift and use the pre-shifted address directly when composing the SPI transfer.

---
 drivers/iio/potentiometer/mcp4131.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/potentiometer/mcp4131.c +1 -1
index ad082827aad5..56c9111ef5e8 100644
@@ -221,7 +221,7 @@ static int mcp4131_write_raw(struct iio_dev *indio_dev,
 
 	mutex_lock(&data->lock);
 
-	data->buf[0] = address << MCP4131_WIPER_SHIFT;
+	data->buf[0] = address;
 	data->buf[0] |= MCP4131_WRITE | (val >> 8);
 	data->buf[1] = val & 0xFF; /* 8 bits here */
 
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 8 lines · On Mon, 2 Feb 2026 21:15:35 +0100 Lukas Schmid <[email protected]> wrote:

The MCP4131 wiper address is shifted twice when preparing the SPI command in mcp4131_write_raw().

The address is already shifted when assigned to the local variable "address", but is then shifted again when written to data->buf[0]. This results in an incorrect command being sent to the device and breaks wiper writes to the second channel.

Quoted 4 lines

Remove the second shift and use the pre-shifted address directly when composing the SPI transfer.

Hi Lukas,

Good find.
Needs a fixes tag though so that we can know how far to backport it. looks like this one goes all the way, so I'll just reply here and pick this up in a minute once my email reaches lore.

Fixes 22d199a53910 ("iio: potentiometer: add driver for Microchip MCP413X/414X/415X/416X/423X/424X/425X/426X")

Thanks,

Jonathan

Quoted 17 lines
---
 drivers/iio/potentiometer/mcp4131.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/potentiometer/mcp4131.c +1 -1
index ad082827aad5..56c9111ef5e8 100644
@@ -221,7 +221,7 @@ static int mcp4131_write_raw(struct iio_dev *indio_dev,
 
 	mutex_lock(&data->lock);
 
-	data->buf[0] = address << MCP4131_WIPER_SHIFT;
+	data->buf[0] = address;
 	data->buf[0] |= MCP4131_WRITE | (val >> 8);
 	data->buf[1] = val & 0xFF; /* 8 bits here */
 
maintainer
#2 lore raw
Quoted 15 lines · On Mon, 2 Feb 2026 20:29:20 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 8 lines · On Mon, 2 Feb 2026 21:15:35 +0100 Lukas Schmid <[email protected]> wrote:

The MCP4131 wiper address is shifted twice when preparing the SPI command in mcp4131_write_raw().

The address is already shifted when assigned to the local variable "address", but is then shifted again when written to data->buf[0]. This results in an incorrect command being sent to the device and breaks wiper writes to the second channel.

Quoted 4 lines

Remove the second shift and use the pre-shifted address directly when composing the SPI transfer.

Quoted 8 lines

Hi Lukas,

Good find.
Needs a fixes tag though so that we can know how far to backport it. looks like this one goes all the way, so I'll just reply here and pick this up in a minute once my email reaches lore.

Fixes 22d199a53910 ("iio: potentiometer: add driver for Microchip MCP413X/414X/415X/416X/423X/424X/425X/426X")

I picked it up by hand. A few things to note for next time. If you do add RESEND then inside the [] so that the tooling maintainers tend to use to pick stuff up (b4 / git am etc) doesn't included the RESEND [PATCH v1] in the title of the commit.

Also, if you resend, please include a comment below the --- on why you did so.

Now applied to my local tree as I'll be rebasing the fixes branch after the release next weekend and am not planning to do a pull request before then.

Thanks,

Jonathan

Quoted 24 lines

Thanks,

Jonathan

Quoted 17 lines
---
 drivers/iio/potentiometer/mcp4131.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/potentiometer/mcp4131.c +1 -1
index ad082827aad5..56c9111ef5e8 100644
@@ -221,7 +221,7 @@ static int mcp4131_write_raw(struct iio_dev *indio_dev,
 
 	mutex_lock(&data->lock);
 
-	data->buf[0] = address << MCP4131_WIPER_SHIFT;
+	data->buf[0] = address;
 	data->buf[0] |= MCP4131_WRITE | (val >> 8);
 	data->buf[1] = val & 0xFF; /* 8 bits here */
 
#3 lore raw
Quoted 33 lines · On Montag, 2. Februar 2026 21:34:43 Mitteleuropäische Normalzeit Jonathan…

On Mon, 2 Feb 2026 20:29:20 +0000

Quoted 18 lines · Jonathan Cameron

On Mon, 2 Feb 2026 21:15:35 +0100

Quoted 8 lines · Lukas Schmid

The MCP4131 wiper address is shifted twice when preparing the SPI command in mcp4131_write_raw().

The address is already shifted when assigned to the local variable "address", but is then shifted again when written to data->buf[0]. This results in an incorrect command being sent to the device and breaks wiper writes to the second channel.

Quoted 4 lines

Remove the second shift and use the pre-shifted address directly when composing the SPI transfer.

Hi Lukas,

Quoted 7 lines

Good find.
Needs a fixes tag though so that we can know how far to backport it. looks like this one goes all the way, so I'll just reply here and pick this up in a minute once my email reaches lore.

Fixes 22d199a53910 ("iio: potentiometer: add driver for Microchip

MCP413X/414X/415X/416X/423X/424X/425X/426X")

I picked it up by hand. A few things to note for next time. If you do add RESEND then inside the [] so that the tooling maintainers tend to use to pick stuff up (b4 / git am etc) doesn't included the RESEND [PATCH v1] in the title of the commit.

Quoted 7 lines

Also, if you resend, please include a comment below the --- on why you did so.

Now applied to my local tree as I'll be rebasing the fixes branch after the release next weekend and am not planning to do a pull request before then.

Hi Jonathan,

thank you for your hints. Will make sure to follow them next time.

Best regards,
Lukas

Quoted 28 lines

Thanks,

Jonathan

Quoted 24 lines

Thanks,

Jonathan

Quoted 20 lines

---

 drivers/iio/potentiometer/mcp4131.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/iio/potentiometer/mcp4131.c index ad082827aad5..56c9111ef5e8 100644

drivers/iio/potentiometer/mcp4131.c +1 -1
@@ -221,7 +221,7 @@ static int mcp4131_write_raw(struct iio_dev
 *indio_dev,
 
 	mutex_lock(&data->lock);
 
-	data->buf[0] = address << MCP4131_WIPER_SHIFT;
+	data->buf[0] = address;
 
 	data->buf[0] |= MCP4131_WRITE | (val >> 8);

data->buf[1] = val & 0xFF; /* 8 bits here */