From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751718AbdGZNib (ORCPT ); Wed, 26 Jul 2017 09:38:31 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:61219 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750781AbdGZNi3 (ORCPT ); Wed, 26 Jul 2017 09:38:29 -0400 From: Arnd Bergmann To: Andrew Morton , Mark Brown , Arnd Bergmann , Masahiro Yamada Cc: Charles Keepax , Tony Lindgren , Michael Grzeschik , Ramesh Shanmugasundaram , "Alex A. Mihaylov" , linux-kernel@vger.kernel.org Subject: [PATCH] [v2] iopoll: avoid -Wint-in-bool-context warning Date: Wed, 26 Jul 2017 15:37:32 +0200 Message-Id: <20170726133756.2161367-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:RWBft+k1+3KNJzZnHxfgExS3ddMXncZBAxD/gkP47viJFgOgIxo PtlBzfpt1/4iB+jsmxhOJ1OonKEcATeZQ8DXprTWl1D8fuR1SvRsKVIelzeaAHcMId3uOHa R29VPEzKlHPluc5imRzmI5CiDO+D9wiGSnRsGQUjQu0jOcWajacGV2D97ZsnDgcDekZ9aAz HS9Cps/m72PEQlL3LEj+Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:4zyyw2vccA0=:KP1A5ohiAmDDzo+bGOHQAT ggjClQkEVl2cVFvbJWguLI0ArrcoI6dCy07YykFSynCVBqLQsAhu/Z2ZwFzIyF2VdVo9ayy3F /Z9HslQdoaWr1W5+eKbjYRRsflMDtMMeD798JdfrEh7e+553BUV19BxqzTJ13JIRvmf6naYE8 uHgK85RWvUgqFAFsttQls2BSYZ8FUE+hI/bDtk9JiiqJqnXA8thNpdk7gIrdNdHl4rlonqgX9 gscMTLuEAVF3amDXUQtmpG4IWWDLhSpEh8i+MjLcwTj+f1owiYJdq9CVNaMncfQn++iBhU2IO Xl0pB2bcd1rzUdUIy+gju2j3xup86xS9UzsKrbpwMI3FVIs3xw+QjveJHJD8bPKbzEqIl8FL5 lIQkjWPn6t7t/bJjgtc2xQIBGOeSiNwKF6+kxsUIEum2ue1vtsQgzgGS5w9h9Kfie4Hg1lcfm Kwngvovg3kHhaixuXmMYmhDPpkvtP7N/6x5pw9ayzvssaSKY3J5VHOkzkgbacfSsdpmds1nrj i8pmIwJ6dZfA2MGjICXqpbtmY14qAz2oT8l91R5rLpgiSRIjjj/nirNHJYGStea/cm27Rzusb 9jLECIE3HQDD7ajYqHYfi/dCjOnxgREvJ8G//PsllpKQLz357sjrIjpKWqa0pVYlQLwm0Urv6 2N5OkBxEx4hTtU3Y0MXLN3QQmAes7LA8mbYqaIn+yZ9C+Gm8Q1VoY3Kb0qntHwxwfBWswTIP0 dZIt4lp/gx2vnavw3l3LzuqtSPdQi88qx46wuQ== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we pass the result of a multiplication as the timeout or the delay, 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] drivers/gpu/drm/sun4i/sun4i_hdmi_i2c.c:49:27: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] The warning is a bit questionable inside of a macro, but this is intentional on the side of the gcc developers. It is also an indication of another problem: we evaluate the timeout and sleep arguments multiple times, which can have undesired side-effects when those are complex expressions. This changes the three iopoll variants to use local variables for storing copies of the timeouts. This adds some more type safety, and avoids both the double-evaluation and the gcc warning. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81484 Signed-off-by: Arnd Bergmann --- v2: - use temporary variables instead of zero-comparison, to avoid double evaluation - also address the delay, not just timout handling --- include/linux/iopoll.h | 24 +++++++++++++++--------- include/linux/regmap.h | 12 +++++++----- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index d29e1e21bf3f..b1d861caca16 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -42,18 +42,21 @@ */ #define readx_poll_timeout(op, addr, val, cond, sleep_us, timeout_us) \ ({ \ - ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \ - might_sleep_if(sleep_us); \ + u64 __timeout_us = (timeout_us); \ + unsigned long __sleep_us = (sleep_us); \ + ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ + might_sleep_if((__sleep_us) != 0); \ for (;;) { \ (val) = op(addr); \ if (cond) \ break; \ - if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \ + if (__timeout_us && \ + ktime_compare(ktime_get(), __timeout) > 0) { \ (val) = op(addr); \ break; \ } \ - if (sleep_us) \ - usleep_range((sleep_us >> 2) + 1, sleep_us); \ + if (__sleep_us) \ + usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ } \ (cond) ? 0 : -ETIMEDOUT; \ }) @@ -77,17 +80,20 @@ */ #define readx_poll_timeout_atomic(op, addr, val, cond, delay_us, timeout_us) \ ({ \ - ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \ + u64 __timeout_us = (timeout_us); \ + unsigned long __delay_us = (delay_us); \ + ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ for (;;) { \ (val) = op(addr); \ if (cond) \ break; \ - if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \ + if (__timeout_us && \ + ktime_compare(ktime_get(), __timeout) > 0) { \ (val) = op(addr); \ break; \ } \ - if (delay_us) \ - udelay(delay_us); \ + if (__delay_us) \ + udelay(__delay_us); \ } \ (cond) ? 0 : -ETIMEDOUT; \ }) diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 1474ab0a3922..a4d30c877f6b 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -120,22 +120,24 @@ struct reg_sequence { */ #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \ ({ \ - ktime_t __timeout = ktime_add_us(ktime_get(), timeout_us); \ + u64 __timeout_us = (timeout_us); \ + unsigned long __sleep_us = (sleep_us); \ + ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ int __ret; \ - might_sleep_if(sleep_us); \ + might_sleep_if(__sleep_us); \ for (;;) { \ __ret = regmap_read((map), (addr), &(val)); \ if (__ret) \ break; \ if (cond) \ break; \ - if ((timeout_us) && \ + if (__timeout_us && \ ktime_compare(ktime_get(), __timeout) > 0) { \ __ret = regmap_read((map), (addr), &(val)); \ break; \ } \ - if (sleep_us) \ - usleep_range(((sleep_us) >> 2) + 1, sleep_us); \ + if (__sleep_us) \ + usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ } \ __ret ?: ((cond) ? 0 : -ETIMEDOUT); \ }) -- 2.9.0