Skip to contentSkip to conversation

gpio: pca953x: remove incorrect le16_to_cpu calls

PATCH Superseded Andy Shevchenko 3 participants 5 messages Jul 3, 2017 – Jul 31, 2017 GPIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: pca953x: remove incorrect le16_to_cpu calls

i2c_smbus commands handle the correct byte order for smbus transactions internally. This will currently result in incorrect operation on big endian systems.

---
 drivers/gpio/gpio-pca953x.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpio/gpio-pca953x.c +3 -5
index 4c9e21300a26..1b9dbf691ae7 100644
@@ -187,10 +187,9 @@ static int pca953x_write_regs_8(struct pca953x_chip *chip, int reg, u8 *val)
 
 static int pca953x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
 {
-	__le16 word = cpu_to_le16(get_unaligned((u16 *)val));
+	u16 word = get_unaligned((u16 *)val);
 
-	return i2c_smbus_write_word_data(chip->client,
-					 reg << 1, (__force u16)word);
+	return i2c_smbus_write_word_data(chip->client, reg << 1, word);
 }
 
 static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
@@ -241,8 +240,7 @@ static int pca953x_read_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
 	int ret;
 
 	ret = i2c_smbus_read_word_data(chip->client, reg << 1);
-	val[0] = (u16)ret & 0xFF;
-	val[1] = (u16)ret >> 8;
+	put_unaligned(ret, (u16 *)val);
 
 	return ret;
 }
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 7 lines · Andy Shevchenko

i2c_smbus commands handle the correct byte order for smbus transactions internally. This will currently result in incorrect operation on big endian systems.

---

-- Sebastian

Quoted 33 lines
 drivers/gpio/gpio-pca953x.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpio/gpio-pca953x.c +3 -5
index 4c9e21300a26..1b9dbf691ae7 100644
@@ -187,10 +187,9 @@ static int pca953x_write_regs_8(struct pca953x_chip *chip, int reg, u8 *val)
 
 static int pca953x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
 {
-	__le16 word = cpu_to_le16(get_unaligned((u16 *)val));
+	u16 word = get_unaligned((u16 *)val);
 
-	return i2c_smbus_write_word_data(chip->client,
-					 reg << 1, (__force u16)word);
+	return i2c_smbus_write_word_data(chip->client, reg << 1, word);
 }
 
 static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
@@ -241,8 +240,7 @@ static int pca953x_read_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
 	int ret;
 
 	ret = i2c_smbus_read_word_data(chip->client, reg << 1);
-	val[0] = (u16)ret & 0xFF;
-	val[1] = (u16)ret >> 8;
+	put_unaligned(ret, (u16 *)val);
 
 	return ret;
 }
Signature · 1 line
2.11.0
#3 lore raw
Quoted 8 lines · Linus Walleij
Quoted 5 lines · Andy Shevchenko

i2c_smbus commands handle the correct byte order for smbus transactions
internally. This will currently result in incorrect operation on big endian systems.

Quoted 4 lines
Quoted 2 lines

Patch applied.

Thanks!

Quoted 3 lines

As I don't see reported regressions it is applied for -next for now.

Luckily we have none, though the latest changes to drivers/nfc/fdp/i2c.c (*) rely on it.

(*) already in v4.13-rc1 IIRC.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#4 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Linus Walleij

On Mon, Jul 3, 2017 at 7:45 PM, Andy Shevchenko
<[email protected]> wrote:

Quoted 8 lines
Quoted 2 lines

As I don't see reported regressions it is applied for -next for now.

Luckily we have none, though the latest changes to drivers/nfc/fdp/i2c.c
(*) rely on it.

(*) already in v4.13-rc1 IIRC.

My gosh! It's for different patch!

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy