i2c: core: fix a code to suppress a warning
Subsystems (2)
PATCH 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 ternary operator.
--- drivers/i2c/i2c-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-core.c +1 -1
@@ -2591,7 +2591,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 ) ?1 :0 ); 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): 1442311867-60185-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]
Alexander Sverdlin
Reviewed-byQuoted 6 lines · EXT Andy Shevchenko
There is a warning when compiling
i2c-core.cdrivers/i2c/i2c-core.c:2561:36: warning: dubious: x | !yFix it by using ternary operator.
Quoted 17 lines
--- drivers/i2c/i2c-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/i2c-core.c +1
-1@@ -2591,7 +2591,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 ) ?1 :0 ); pec =i2c_smbus_pec (pec, &addr,1 );/* The data buffer follows */
Signature · 2 lines
Best regards, Alexander Sverdlin.
Hello Andy,
Quoted 16 lines · Andy Shevchenko
There is a warning when compiling
i2c-core.cdrivers/i2c/i2c-core.c:2561:36: warning: dubious: x | !yFix it by using ternary operator.
--- drivers/i2c/i2c-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/i2c-core.c +0
-0
drivers/i2c/i2c-core.c static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count) · line 2597
Quoted 8 lines
drivers/i2c/i2c-core.c +1
-1@@ -2591,7 +2591,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 ) ?1 :0 ); pec =i2c_smbus_pec (pec, &addr,1 );/* The data buffer follows */
I2C_M_RD is defined as 1, probably (msg->flags & I2C_M_RD) is good enough here.
--
With best wishes,
Vladimir
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 27 lines · Vladimir Zapolskiy
Hello Andy,
Quoted 24 lines · Andy Shevchenko
There is a warning when compiling
i2c-core.cdrivers/i2c/i2c-core.c:2561:36: warning: dubious: x | !yFix it by using ternary operator.
--- drivers/i2c/i2c-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/i2c-core.c +1
-1@@ -2591,7 +2591,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 ) ?1 :0 ); pec =i2c_smbus_pec (pec, &addr,1 );
Quoted 5 lines
Quoted 2 lines
/* The data buffer follows */
I2C_M_RDis defined as 1, probably (msg->flags&I2C_M_RD) is good enough here.
Today is 1, tomorrow is 0x80, so, I would stay as I put in the initial fix.
Quoted 4 lines
--
With best wishes,
Vladimir
Signature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy
A message that is not in the archive (sent off-list or not yet received): 1442318818.8361.29.camel-VuQAYsv1563Yd54FQh9/[email protected]
Quoted 28 lines · Andy Shevchenko
Quoted 27 lines · Vladimir Zapolskiy
Hello Andy,
Quoted 24 lines · Andy Shevchenko
There is a warning when compiling
i2c-core.cdrivers/i2c/i2c-core.c:2561:36: warning: dubious: x | !yFix it by using ternary operator.
--- drivers/i2c/i2c-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/i2c-core.c +1
-1@@ -2591,7 +2591,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 ) ?1 :0 ); pec =i2c_smbus_pec (pec, &addr,1 );
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
/* The data buffer follows */
I2C_M_RDis defined as 1, probably (msg->flags&I2C_M_RD) is good enough here.Today is 1, tomorrow is
0x80, so, I would stay as I put in the initial fix.
I believe I2C_M_RD will never get any other value than 1, since this value is deliberately set to 1 and it is in active use by userspace applications for years, nobody intends to break ABI tomorrow.
--
With best wishes,
Vladimir
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
I2C_M_RDis defined as 1, probably (msg->flags&I2C_M_RD) is good enough here.Today is 1, tomorrow is
0x80, so, I would stay as I put in the initial fix.I believe
I2C_M_RDwill never get any other value than 1, since this value is deliberately set to 1 and it is in active use by userspace applications for years, nobody intends to break ABI tomorrow.
I agree. That is one thing that permanently slips through the cracks, but I wanted to add a comment saying the I2C_M_RD is guaranteed to be 1 and then simplify the drivers.
Maybe I should start with the comment right now...
Quoted 14 lines · Wolfram Sang
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
I2C_M_RDis defined as 1, probably (msg->flags&I2C_M_RD) is good
enough here.Quoted 8 lines
Quoted 3 lines
Today is 1, tomorrow is
0x80, so, I would stay as I put in the initial
fix.I believe
I2C_M_RDwill never get any other value than 1, since this
value is deliberately set to 1 and it is in active use by userspace applications for years, nobody intends to break ABI tomorrow.
Quoted 4 lines
I agree. That is one thing that permanently slips through the cracks, but I wanted to add a comment saying the
I2C_M_RDis guaranteed to be 1
and then simplify the drivers.
Yes, with comment on I2C_M_RD we may drop wrong assumptions.
Quoted 2 lines
Maybe I should start with the comment right now...
Please, update my patch accordingly, or ping me to update it. Right now busy with something else.
Signature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy