Skip to contentSkip to conversation

i2c: misplaced parentheses?

PATCH In review Roel Kluin 2 participants 2 messages Feb 15, 2009 – Feb 16, 2009 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 i2c: misplaced parentheses?

I think below is what was intended? otherwise we could as well have written:

msg[0].flags = flags || (read_write == I2C_SMBUS_READ) ? I2C_M_RD : 0;

please review. -------------------------->8------------------8<--------------------------- Fix misplaced parentheses

---

drivers/i2c/i2c-core.c +2 -1
index b1c9abe..2d34a7a 100644
@@ -1831,7 +1831,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
 	case I2C_SMBUS_QUICK:
 		msg[0].len = 0;
 		/* Special case: The read/write field is used as data */
-		msg[0].flags = flags | (read_write==I2C_SMBUS_READ)?I2C_M_RD:0;
+		msg[0].flags = flags | (read_write == I2C_SMBUS_READ ?
+				I2C_M_RD : 0);
 		num = 1;
 		break;
 	case I2C_SMBUS_BYTE:
#2 lore raw
In reply to a message not in the archive

Hi Roel,

Quoted 3 lines · Roel Kluin

I think below is what was intended? otherwise we could as well have written:

msg[0].flags = flags || (read_write == I2C_SMBUS_READ) ? I2C_M_RD : 0;

Which would clearly be wrong, as flags is a bit field.

Quoted 12 lines

please review. -------------------------->8------------------8<--------------------------- Fix misplaced parentheses

---

drivers/i2c/i2c-core.c +0 -0
index b1c9abe..2d34a7a 100644

drivers/i2c/i2c-core.c static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, · line 1838

Quoted 9 lines
drivers/i2c/i2c-core.c +2 -1
@@ -1831,7 +1831,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
 	case I2C_SMBUS_QUICK:
 		msg[0].len = 0;
 		/* Special case: The read/write field is used as data */
-		msg[0].flags = flags | (read_write==I2C_SMBUS_READ)?I2C_M_RD:0;
+		msg[0].flags = flags | (read_write == I2C_SMBUS_READ ?
+				I2C_M_RD : 0);
 		num = 1;
 		break;
 	case I2C_SMBUS_BYTE:

You are perfectly right. We are probably just lucky that in most cases flags is 0 so both expressions are equivalent. Otherwise we'd have noticed the bug earlier I guess.

Patch applied, thanks.

Signature · 1 line
Jean Delvare