Re: [PATCH 13/14] iopoll: avoid -Wint-in-bool-context warning

2017-07-14 Thread Arnd Bergmann
On Fri, Jul 14, 2017 at 11:55 AM, Joe Perches  wrote:
> On Fri, 2017-07-14 at 11:31 +0200, Arnd Bergmann wrote:
>> When we pass the result of a multiplication as the timeout, we
>> can get a warning:
>>
>> drivers/mmc/host/bcm2835.c:596:149: error: '*' in boolean context, suggest 
>> '&&' instead [-Werror=int-in-bool-context]
>> drivers/mfd/arizona-core.c:247:195: error: '*' in boolean context, suggest 
>> '&&' instead [-Werror=int-in-bool-context]
>>
>> This is easy to avoid by comparing the timeout to zero instead,
>> making it a boolean expression.
>
> Perhaps this is better as != 0 if the multiply is signed.

I thought about that, but decided that as a negative timeout_us already
gives us rather random behavior (ktime_add_us() takes an unsigned
argument), the '>' comparison gives a more well-defined result by
ignoring the timeout.

 Arnd


Re: [PATCH 13/14] iopoll: avoid -Wint-in-bool-context warning

2017-07-14 Thread Joe Perches
On Fri, 2017-07-14 at 11:31 +0200, Arnd Bergmann wrote:
> When we pass the result of a multiplication as the timeout, we
> can get a warning:
> 
> drivers/mmc/host/bcm2835.c:596:149: error: '*' in boolean context, suggest 
> '&&' instead [-Werror=int-in-bool-context]
> drivers/mfd/arizona-core.c:247:195: error: '*' in boolean context, suggest 
> '&&' instead [-Werror=int-in-bool-context]
> 
> This is easy to avoid by comparing the timeout to zero instead,
> making it a boolean expression.

Perhaps this is better as != 0 if the multiply is signed.

> diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h
[]
> @@ -48,7 +48,8 @@
>   (val) = op(addr); \
>   if (cond) \
>   break; \
> - if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
> + if ((timeout_us) > 0 && \
> + ktime_compare(ktime_get(), timeout) > 0) { \
>   (val) = op(addr); \
>   break; \
>   } \

etc...


[PATCH 13/14] iopoll: avoid -Wint-in-bool-context warning

2017-07-14 Thread Arnd Bergmann
When we pass the result of a multiplication as the timeout, we
can get a warning:

drivers/mmc/host/bcm2835.c:596:149: error: '*' in boolean context, suggest '&&' 
instead [-Werror=int-in-bool-context]
drivers/mfd/arizona-core.c:247:195: error: '*' in boolean context, suggest '&&' 
instead [-Werror=int-in-bool-context]

This is easy to avoid by comparing the timeout to zero instead,
making it a boolean expression.

Signed-off-by: Arnd Bergmann 
---
 include/linux/iopoll.h | 6 --
 include/linux/regmap.h | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h
index d29e1e21bf3f..7a17ba02253b 100644
--- a/include/linux/iopoll.h
+++ b/include/linux/iopoll.h
@@ -48,7 +48,8 @@
(val) = op(addr); \
if (cond) \
break; \
-   if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
+   if ((timeout_us) > 0 && \
+   ktime_compare(ktime_get(), timeout) > 0) { \
(val) = op(addr); \
break; \
} \
@@ -82,7 +83,8 @@
(val) = op(addr); \
if (cond) \
break; \
-   if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
+   if ((timeout_us) > 0 && \
+   ktime_compare(ktime_get(), timeout) > 0) { \
(val) = op(addr); \
break; \
} \
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 1474ab0a3922..0889dbf37161 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -129,7 +129,7 @@ struct reg_sequence {
break; \
if (cond) \
break; \
-   if ((timeout_us) && \
+   if ((timeout_us) > 0 && \
ktime_compare(ktime_get(), __timeout) > 0) { \
__ret = regmap_read((map), (addr), &(val)); \
break; \
-- 
2.9.0