linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: uniphier[-f]: fix bool logic calculation
@ 2016-10-19  4:38 Masahiro Yamada
  2016-12-20 16:20 ` Masahiro Yamada
  0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2016-10-19  4:38 UTC (permalink / raw)
  To: linux-i2c; +Cc: Masahiro Yamada, linux-arm-kernel, linux-kernel, Wolfram Sang

This code is working, but it should not depend on how "bool" is
typedef'ed, or the bit position of I2C_M_RD.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 drivers/i2c/busses/i2c-uniphier-f.c | 2 +-
 drivers/i2c/busses/i2c-uniphier.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c
index db9105e..b54448e 100644
--- a/drivers/i2c/busses/i2c-uniphier-f.c
+++ b/drivers/i2c/busses/i2c-uniphier-f.c
@@ -309,7 +309,7 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap,
 					 struct i2c_msg *msg, bool stop)
 {
 	struct uniphier_fi2c_priv *priv = i2c_get_adapdata(adap);
-	bool is_read = msg->flags & I2C_M_RD;
+	bool is_read = !!(msg->flags & I2C_M_RD);
 	unsigned long time_left;
 
 	dev_dbg(&adap->dev, "%s: addr=0x%02x, len=%d, stop=%d\n",
diff --git a/drivers/i2c/busses/i2c-uniphier.c b/drivers/i2c/busses/i2c-uniphier.c
index 56e92af..cc80bb2 100644
--- a/drivers/i2c/busses/i2c-uniphier.c
+++ b/drivers/i2c/busses/i2c-uniphier.c
@@ -177,7 +177,7 @@ static int uniphier_i2c_stop(struct i2c_adapter *adap)
 static int uniphier_i2c_master_xfer_one(struct i2c_adapter *adap,
 					struct i2c_msg *msg, bool stop)
 {
-	bool is_read = msg->flags & I2C_M_RD;
+	bool is_read = !!(msg->flags & I2C_M_RD);
 	bool recovery = false;
 	int ret;
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: uniphier[-f]: fix bool logic calculation
  2016-10-19  4:38 [PATCH] i2c: uniphier[-f]: fix bool logic calculation Masahiro Yamada
@ 2016-12-20 16:20 ` Masahiro Yamada
  2016-12-20 17:55   ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2016-12-20 16:20 UTC (permalink / raw)
  To: linux-i2c
  Cc: Masahiro Yamada, Linux Kernel Mailing List, linux-arm-kernel,
	Wolfram Sang

Hi.

I have not got any comment, but does this seem
a right thing to do?

2016-10-19 13:38 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> This code is working, but it should not depend on how "bool" is
> typedef'ed, or the bit position of I2C_M_RD.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
>  drivers/i2c/busses/i2c-uniphier-f.c | 2 +-
>  drivers/i2c/busses/i2c-uniphier.c   | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c
> index db9105e..b54448e 100644
> --- a/drivers/i2c/busses/i2c-uniphier-f.c
> +++ b/drivers/i2c/busses/i2c-uniphier-f.c
> @@ -309,7 +309,7 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap,
>                                          struct i2c_msg *msg, bool stop)
>  {
>         struct uniphier_fi2c_priv *priv = i2c_get_adapdata(adap);
> -       bool is_read = msg->flags & I2C_M_RD;
> +       bool is_read = !!(msg->flags & I2C_M_RD);
>         unsigned long time_left;
>
>         dev_dbg(&adap->dev, "%s: addr=0x%02x, len=%d, stop=%d\n",
> diff --git a/drivers/i2c/busses/i2c-uniphier.c b/drivers/i2c/busses/i2c-uniphier.c
> index 56e92af..cc80bb2 100644
> --- a/drivers/i2c/busses/i2c-uniphier.c
> +++ b/drivers/i2c/busses/i2c-uniphier.c
> @@ -177,7 +177,7 @@ static int uniphier_i2c_stop(struct i2c_adapter *adap)
>  static int uniphier_i2c_master_xfer_one(struct i2c_adapter *adap,
>                                         struct i2c_msg *msg, bool stop)
>  {
> -       bool is_read = msg->flags & I2C_M_RD;
> +       bool is_read = !!(msg->flags & I2C_M_RD);
>         bool recovery = false;
>         int ret;
>
> --
> 1.9.1
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: uniphier[-f]: fix bool logic calculation
  2016-12-20 16:20 ` Masahiro Yamada
@ 2016-12-20 17:55   ` Joe Perches
  2016-12-21 15:39     ` Masahiro Yamada
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2016-12-20 17:55 UTC (permalink / raw)
  To: Masahiro Yamada, linux-i2c
  Cc: Linux Kernel Mailing List, linux-arm-kernel, Wolfram Sang

On Wed, 2016-12-21 at 01:20 +0900, Masahiro Yamada wrote:
> Hi.
> 
> I have not got any comment, but does this seem
> a right thing to do?

> This code is working, but it should not depend on how "bool" is
> typedef'ed, or the bit position of I2C_M_RD.

<shrug>

I think bool can be guaranteed to be _Bool.

So a change not necessary as the original code
has a c90 guarantee of the same result.

6.3.1.2 Boolean type
1
When any scalar value is converted to _Bool, the result is 0 if the value compares equal
to 0; otherwise, the result is 1.


> 2016-10-19 13:38 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
[]
> > diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c
[]
> > @@ -309,7 +309,7 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap,
> >                                          struct i2c_msg *msg, bool stop)
> >  {
> >         struct uniphier_fi2c_priv *priv = i2c_get_adapdata(adap);
> > -       bool is_read = msg->flags & I2C_M_RD;
> > +       bool is_read = !!(msg->flags & I2C_M_RD);
> >         unsigned long time_left;
> > 
> >         dev_dbg(&adap->dev, "%s: addr=0x%02x, len=%d, stop=%d\n",

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: uniphier[-f]: fix bool logic calculation
  2016-12-20 17:55   ` Joe Perches
@ 2016-12-21 15:39     ` Masahiro Yamada
  0 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2016-12-21 15:39 UTC (permalink / raw)
  To: Joe Perches
  Cc: linux-i2c, Linux Kernel Mailing List, linux-arm-kernel, Wolfram Sang

Hi Joe,


2016-12-21 2:55 GMT+09:00 Joe Perches <joe@perches.com>:
> On Wed, 2016-12-21 at 01:20 +0900, Masahiro Yamada wrote:
>> Hi.
>>
>> I have not got any comment, but does this seem
>> a right thing to do?
>
>> This code is working, but it should not depend on how "bool" is
>> typedef'ed, or the bit position of I2C_M_RD.
>
> <shrug>
>
> I think bool can be guaranteed to be _Bool.
>
> So a change not necessary as the original code
> has a c90 guarantee of the same result.
>
> 6.3.1.2 Boolean type
> 1
> When any scalar value is converted to _Bool, the result is 0 if the value compares equal
> to 0; otherwise, the result is 1.
>

Thanks for your comments!

_Bool works very nicely.

I have seen some (not very nice) projects
that define like "typedef char bool;"

So, I was wondering if I should write code
that works regardless how bool is defined.
Just my two cents.

-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-21 15:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-19  4:38 [PATCH] i2c: uniphier[-f]: fix bool logic calculation Masahiro Yamada
2016-12-20 16:20 ` Masahiro Yamada
2016-12-20 17:55   ` Joe Perches
2016-12-21 15:39     ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).