Skip to contentSkip to conversation

gpio: pca953x: enfore type for i2c_smbus_write_word_data()

PATCH In review Andy Shevchenko 3 participants 8 messages May 31, 2016 – Jun 8, 2016 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: pca953x: enfore type for i2c_smbus_write_word_data()

The commit 9b8e3ec34318 ("gpio: pca953x: Use correct u16 value for register word write") fixed regression in pca953x_write_regs(). At the same time the solution introduced a sparse warning:

drivers/gpio/gpio-pca953x.c:168:39: warning: incorrect type in argument 3 (different base types)
drivers/gpio/gpio-pca953x.c:168:39: expected unsigned short [unsigned] [usertype] value
drivers/gpio/gpio-pca953x.c:168:39: got restricted __le16 [usertype] <noident>

Fix the code by enforcing the type of i2c_smbus_write_word_data() parameter.

---
 drivers/gpio/gpio-pca953x.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio-pca953x.c +6 -3
index d8233be..21b21cd 100644
@@ -163,10 +163,13 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val)
 					NBANK(chip), val);
 	} else {
 		switch (chip->chip_type) {
-		case PCA953X_TYPE:
-			ret = i2c_smbus_write_word_data(chip->client,
-			    reg << 1, cpu_to_le16(get_unaligned((u16 *)val)));
+		case PCA953X_TYPE: {
+			__le16 word = cpu_to_le16(get_unaligned((u16 *)val));
+
+			ret = i2c_smbus_write_word_data(chip->client, reg << 1,
+							(__force u16)word);
 			break;
+		}
 		case PCA957X_TYPE:
 			ret = i2c_smbus_write_byte_data(chip->client, reg << 1,
 							val[0]);
Signature · 1 line
2.8.1
#1 lore raw

Hi Andy,

Could you let me know which build system you are using? I am using Ubuntu 1604(64 bit) to build the kernel source, but I did not find the warning.

Thanks,
Yong

2016-06-01 3:03 GMT+08:00 Andy Shevchenko <[email protected]>:

Quoted 41 lines

The commit 9b8e3ec34318 ("gpio: pca953x: Use correct u16 value for register word write") fixed regression in pca953x_write_regs(). At the same time the solution introduced a sparse warning:

drivers/gpio/gpio-pca953x.c:168:39: warning: incorrect type in argument 3 (different base types)
drivers/gpio/gpio-pca953x.c:168:39: expected unsigned short [unsigned] [usertype] value
drivers/gpio/gpio-pca953x.c:168:39: got restricted __le16 [usertype] <noident>

Fix the code by enforcing the type of i2c_smbus_write_word_data() parameter.

---
 drivers/gpio/gpio-pca953x.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio-pca953x.c +6 -4
index d8233be..21b21cd 100644
@@ -163,10 +163,13 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val)
                                        NBANK(chip), val);
        } else {
                switch (chip->chip_type) {
-               case PCA953X_TYPE:
-                       ret = i2c_smbus_write_word_data(chip->client,
-                           reg << 1, cpu_to_le16(get_unaligned((u16 *)val)));
+               case PCA953X_TYPE: {
+                       __le16 word = cpu_to_le16(get_unaligned((u16 *)val));
+
+                       ret = i2c_smbus_write_word_data(chip->client, reg << 1,
+                                                       (__force u16)word);
                        break;
+               }
                case PCA957X_TYPE:
                        ret = i2c_smbus_write_byte_data(chip->client, reg << 1,
                                                        val[0]);
--

2.8.1

#2 lore raw
Quoted 5 lines · Yong Li

Hi Andy,

Could you let me know which build system you are using? I am using Ubuntu 1604(64 bit) to build the kernel source, but I did not find the warning.

Hmm... I'm confused what exactly you are asking here. My host system is Debian unstable, kernel is built by it's own KBuild infrastructure.

I'm pretty sure you are talking about this:

https://lwn.net/Articles/205624/

Quoted 61 lines

Thanks,
Yong

2016-06-01 3:03 GMT+08:00 Andy Shevchenko <[email protected] el.com>:

Quoted 55 lines

The commit 9b8e3ec34318 ("gpio: pca953x: Use correct u16 value for register
word write") fixed regression in pca953x_write_regs(). At the same time the
solution introduced a sparse warning:

drivers/gpio/gpio-pca953x.c:168:39: warning: incorrect type in argument 3 (different base types) drivers/gpio/gpio-pca953x.c:168:39:    expected unsigned short [unsigned] [usertype] value drivers/gpio/gpio-pca953x.c:168:39:    got restricted __le16 [usertype] <noident>

Fix the code by enforcing the type of i2c_smbus_write_word_data() parameter.

---
 drivers/gpio/gpio-pca953x.c | 9 ++++++---

 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio- renamed from drivers/gpio/gpio-pca953x.c +0 -0

pca953x.c
index d8233be..21b21cd 100644

drivers/gpio/gpio-pca953x.c +4 -3
@@ -163,10 +163,13 @@ static int pca953x_write_regs(struct
 pca953x_chip *chip, int reg, u8 *val)
                                         NBANK(chip), val);
         } else {
                 switch (chip->chip_type) {
-               case PCA953X_TYPE:
-                       ret = i2c_smbus_write_word_data(chip-
 >client,
-                           reg << 1, cpu_to_le16(get_unaligned((u16
 *)val)));
+               case PCA953X_TYPE: {
+                       __le16 word = cpu_to_le16(get_unaligned((u16
 *)val));
+
+                       ret = i2c_smbus_write_word_data(chip-
Quoted 1 line

client, reg << 1,

+                                                       (__force u16)word);
                        break;
+               }
                case PCA957X_TYPE:
                        ret = i2c_smbus_write_byte_data(chip-

Quoted 1 line

client, reg << 1,

                                                        val[0]); --
2.8.1

Signature · 6 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

Hi andy,

Sorry for the confusing. I tested the patch today, using Ubuntu 1604 + gcc 5.3, the make bzImage does not output any warning messages about this .c file. I am wondering how you captured the warnings. It seems that I need the "make C=2" command.

Thanks,
Yong

2016-06-01 20:35 GMT+08:00 Andy Shevchenko <[email protected]>:

Quoted 79 lines · Yong Li
Quoted 5 lines

Hi Andy,

Could you let me know which build system you are using? I am using Ubuntu 1604(64 bit) to build the kernel source, but I did not find the warning.

Hmm... I'm confused what exactly you are asking here. My host system is Debian unstable, kernel is built by it's own KBuild infrastructure.

I'm pretty sure you are talking about this:

https://lwn.net/Articles/205624/

Quoted 61 lines

Thanks,
Yong

2016-06-01 3:03 GMT+08:00 Andy Shevchenko <[email protected] el.com>:

Quoted 55 lines

The commit 9b8e3ec34318 ("gpio: pca953x: Use correct u16 value for register
word write") fixed regression in pca953x_write_regs(). At the same time the
solution introduced a sparse warning:

drivers/gpio/gpio-pca953x.c:168:39: warning: incorrect type in argument 3 (different base types)
drivers/gpio/gpio-pca953x.c:168:39: expected unsigned short
[unsigned] [usertype] value
drivers/gpio/gpio-pca953x.c:168:39: got restricted __le16
[usertype] <noident>

Fix the code by enforcing the type of i2c_smbus_write_word_data() parameter.

---
 drivers/gpio/gpio-pca953x.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio- renamed from drivers/gpio/gpio-pca953x.c +0 -0

pca953x.c
index d8233be..21b21cd 100644

drivers/gpio/gpio-pca953x.c +4 -3
@@ -163,10 +163,13 @@ static int pca953x_write_regs(struct
 pca953x_chip *chip, int reg, u8 *val)
                                        NBANK(chip), val);
        } else {
                switch (chip->chip_type) {
-               case PCA953X_TYPE:
-                       ret = i2c_smbus_write_word_data(chip-
 >client,
-                           reg << 1, cpu_to_le16(get_unaligned((u16
 *)val)));
+               case PCA953X_TYPE: {
+                       __le16 word = cpu_to_le16(get_unaligned((u16
 *)val));
+
+                       ret = i2c_smbus_write_word_data(chip-
Quoted 1 line

client, reg << 1,

+ (__force

u16)word);
                        break;

+ }
case PCA957X_TYPE:
ret = i2c_smbus_write_byte_data(chip-

Quoted 1 line

client, reg << 1,

                                                        val[0]);

--
2.8.1

--
Andy Shevchenko <[email protected]> Intel Finland Oy

#4 lore raw
Quoted 6 lines · Yong Li

Hi andy,

Sorry for the confusing. I tested the patch today, using Ubuntu 1604 + gcc 5.3, the make bzImage does not output any warning messages about this .c file. I am wondering how you captured the warnings. It seems that I need the "make C=2" command.

It requires to explicitly enable endianess check via CF= parameter.

Linus, by the way do we need to go with this to stable and -rc2?

Quoted 94 lines

Thanks,
Yong

2016-06-01 20:35 GMT+08:00 Andy Shevchenko <[email protected] tel.com>:

Quoted 88 lines · Yong Li
Quoted 6 lines

Hi Andy,

Could you let me know which build system you are using? I am using Ubuntu 1604(64 bit) to build the kernel source, but I did not find the
warning.

Hmm... I'm confused what exactly you are asking here. My host system is
Debian unstable, kernel is built by it's own KBuild infrastructure.

I'm pretty sure you are talking about this:

https://lwn.net/Articles/205624/

Quoted 68 lines

Thanks,
Yong

2016-06-01 3:03 GMT+08:00 Andy Shevchenko <andriy.shevchenko@linux .int
el.com>:

Quoted 61 lines

The commit 9b8e3ec34318 ("gpio: pca953x: Use correct u16 value for
register
word write") fixed regression in pca953x_write_regs(). At the same
time the
solution introduced a sparse warning:

drivers/gpio/gpio-pca953x.c:168:39: warning: incorrect type in argument 3 (different base types) drivers/gpio/gpio-pca953x.c:168:39:    expected unsigned short [unsigned] [usertype] value drivers/gpio/gpio-pca953x.c:168:39:    got restricted __le16 [usertype] <noident>

Fix the code by enforcing the type of
i2c_smbus_write_word_data()
parameter.

m>
---
 drivers/gpio/gpio-pca953x.c | 9 ++++++---

 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio- renamed from drivers/gpio/gpio-pca953x.c +0 -0

pca953x.c
index d8233be..21b21cd 100644

drivers/gpio/gpio-pca953x.c +0 -3
@@ -163,10 +163,13 @@ static int pca953x_write_regs(struct
 pca953x_chip *chip, int reg, u8 *val)
                                         NBANK(chip), val);
         } else {
                 switch (chip->chip_type) {
-               case PCA953X_TYPE:
-                       ret = i2c_smbus_write_word_data(chip-
 > client,
-                           reg << 1,

cpu_to_le16(get_unaligned((u16
*)val)));
+               case PCA953X_TYPE: {
+                       __le16 word = cpu_to_le16(get_unaligned((u16
*)val));
+
+                       ret = i2c_smbus_write_word_data(chip-

Quoted 1 line

client, reg << 1,

+                                                       (__force u16)word);
                        break;
+               }
                case PCA957X_TYPE:
                        ret = i2c_smbus_write_byte_data(chip-

Quoted 1 line

client, reg << 1,

                                                        val[0]); --
2.8.1

--
Andy Shevchenko <[email protected]> Intel Finland Oy

Signature · 6 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
Quoted 1 line · Andy Shevchenko

Linus, by the way do we need to go with this to stable and -rc2?

If it's just a compilation warning, no.

If it is causing real regressions on hardware yes.

I have applied it for the next kernel as of now.

Yours,
Linus Walleij

#6 lore raw
Quoted 8 lines · Linus Walleij
Quoted 1 line · Andy Shevchenko

Linus, by the way do we need to go with this to stable and -rc2?

If it's just a compilation warning, no.

If it is causing real regressions on hardware yes.

I believe it's just a static analyzer warning.

Quoted 2 lines

I have applied it for the next kernel as of now.

Thanks!

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#7 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

The commit 9b8e3ec34318 ("gpio: pca953x: Use correct u16 value for register word write") fixed regression in pca953x_write_regs(). At the same time the solution introduced a sparse warning:

drivers/gpio/gpio-pca953x.c:168:39: warning: incorrect type in argument 3 (different base types)
drivers/gpio/gpio-pca953x.c:168:39: expected unsigned short [unsigned] [usertype] value
drivers/gpio/gpio-pca953x.c:168:39: got restricted __le16 [usertype] <noident>

Quoted 5 lines

Fix the code by enforcing the type of i2c_smbus_write_word_data() parameter.

Patch applied.

Yours,
Linus Walleij