diff mbox

[1/1] i2c: core: fix a code to suppress a warning

Message ID 1442311867-60185-1-git-send-email-andriy.shevchenko@linux.intel.com
State Superseded
Headers show

Commit Message

Andy Shevchenko Sept. 15, 2015, 10:11 a.m. UTC
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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/i2c-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alexander A Sverdlin Sept. 15, 2015, 11:23 a.m. UTC | #1
On 15/09/15 12:11, EXT Andy Shevchenko wrote:
> 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.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
> ---
>  drivers/i2c/i2c-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 3a4c54e..d13a8a0 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -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 */
Vladimir Zapolskiy Sept. 15, 2015, 11:25 a.m. UTC | #2
Hello Andy,

On 15.09.2015 13:11, Andy Shevchenko wrote:
> 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.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/i2c/i2c-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 3a4c54e..d13a8a0 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -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
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Shevchenko Sept. 15, 2015, 12:06 p.m. UTC | #3
On Tue, 2015-09-15 at 14:25 +0300, Vladimir Zapolskiy wrote:
> Hello Andy,
> 
> On 15.09.2015 13:11, Andy Shevchenko wrote:
> > 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.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  drivers/i2c/i2c-core.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> > index 3a4c54e..d13a8a0 100644
> > --- a/drivers/i2c/i2c-core.c
> > +++ b/drivers/i2c/i2c-core.c
> > @@ -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.

Today is 1, tomorrow is 0x80, so, I would stay as I put in the initial
fix.

> 
> --
> With best wishes,
> Vladimir
Vladimir Zapolskiy Sept. 15, 2015, 12:47 p.m. UTC | #4
On 15.09.2015 15:06, Andy Shevchenko wrote:
> On Tue, 2015-09-15 at 14:25 +0300, Vladimir Zapolskiy wrote:
>> Hello Andy,
>>
>> On 15.09.2015 13:11, Andy Shevchenko wrote:
>>> 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.
>>>
>>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>>> ---
>>>  drivers/i2c/i2c-core.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
>>> index 3a4c54e..d13a8a0 100644
>>> --- a/drivers/i2c/i2c-core.c
>>> +++ b/drivers/i2c/i2c-core.c
>>> @@ -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.
> 
> 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


--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang Sept. 15, 2015, 1 p.m. UTC | #5
> >> I2C_M_RD is 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.

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...
Andy Shevchenko Sept. 15, 2015, 1:34 p.m. UTC | #6
On Tue, 2015-09-15 at 15:00 +0200, Wolfram Sang wrote:
> > 
> > > > I2C_M_RD is 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.
> 
> 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.

Yes, with comment on I2C_M_RD we may drop wrong assumptions.

> 
> 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.
diff mbox

Patch

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 3a4c54e..d13a8a0 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -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 */