Skip to contentSkip to conversation

i2c: core: fix a code to suppress a warning

PATCH In review Andy Shevchenko 4 participants 4 messages Sep 18, 2015 – Dec 1, 2015 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c: core: fix a code to suppress a warning

There is a warning when compiling i2c-core.c drivers/i2c/i2c-core.c:2561:36: warning: dubious: x | !y

Fix it by using a plain bitwise AND since I2C_M_RD is a bit 0 and thus we are on the safe side.

---
 drivers/i2c/i2c-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-core.c +1 -1
index 5f89f1e..a732107 100644
@@ -2555,7 +2555,7 @@ static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count)
 static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg)
 {
 	/* The address will be sent first */
-	u8 addr = (msg->addr << 1) | !!(msg->flags & I2C_M_RD);
+	u8 addr = (msg->addr << 1) | (msg->flags & I2C_M_RD);
 	pec = i2c_smbus_pec(pec, &addr, 1);
 
 	/* The data buffer follows */
Signature · 1 line
2.5.1

A message that is not in the archive (sent off-list or not yet received): 1442574399-26131-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]

Reviewed-by
#2 lore raw
Quoted 7 lines · EXT Andy Shevchenko

There is a warning when compiling i2c-core.c drivers/i2c/i2c-core.c:2561:36: warning: dubious: x | !y

Fix it by using a plain bitwise AND since I2C_M_RD is a bit 0 and thus we are on the safe side.

Quoted 17 lines
---
 drivers/i2c/i2c-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-core.c +1 -1
index 5f89f1e..a732107 100644
@@ -2555,7 +2555,7 @@ static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count)
 static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg)
 {
 	/* The address will be sent first */
-	u8 addr = (msg->addr << 1) | !!(msg->flags & I2C_M_RD);
+	u8 addr = (msg->addr << 1) | (msg->flags & I2C_M_RD);
 	pec = i2c_smbus_pec(pec, &addr, 1);
 
 	/* The data buffer follows */
Signature · 2 lines
Best regards,
Alexander Sverdlin.
#3 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

There is a warning when compiling i2c-core.c drivers/i2c/i2c-core.c:2561:36: warning: dubious: x | !y

Fix it by using a plain bitwise AND since I2C_M_RD is a bit 0 and thus we are
on the safe side.

Wolfram, as of today I didn't see this in linux-next. Should I amend this one somehow?

Quoted 20 lines

---
 drivers/i2c/i2c-core.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-core.c +1 -1
index 5f89f1e..a732107 100644
@@ -2555,7 +2555,7 @@ static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t
 count)
  static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg)
  {
  	/* The address will be sent first */
-	u8 addr = (msg->addr << 1) | !!(msg->flags & I2C_M_RD);
+	u8 addr = (msg->addr << 1) | (msg->flags & I2C_M_RD);
  	pec = i2c_smbus_pec(pec, &addr, 1);


  /* The data buffer follows */

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

There is a warning when compiling i2c-core.c drivers/i2c/i2c-core.c:2561:36: warning: dubious: x | !y

Fix it by using a plain bitwise AND since I2C_M_RD is a bit 0 and thus we are
on the safe side.

Wolfram, as of today I didn't see this in linux-next. Should I amend this one somehow?

I am working on my own series, introducing a macro for this operation which can be used in drivers, too. Just need to fiddle a little more with my coccinelle scripts. Stay tuned!

Thanks,

Wolfram