From patchwork Wed Jul 26 13:37:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 108759 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp812956qge; Wed, 26 Jul 2017 06:38:33 -0700 (PDT) X-Received: by 10.98.44.200 with SMTP id s191mr868060pfs.105.1501076313466; Wed, 26 Jul 2017 06:38:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501076313; cv=none; d=google.com; s=arc-20160816; b=hrJRlmKA9LQ+WaNdMT8oER8t/MIc0h3E7f+jYzirvHvgqV88PahPACQCQnrs5b27rB byloAX6MsZilh37EqG1HmHUSXIwO5HfCbfbvwn4NJs15hnBzghdpis42d18eJONGqDY5 FjmhHY64eCyzUxE2urTTC1P1hyBzPh25KqtTI6q8XjzbFM8SaeLSeDsGUJS9Tx9CnIAp JM/b4ByCCRWmYL6P7EGxwjSm7ZvroH6hKRU/HuClJQB63VoobP7moolptNcgLrq8pg9M DHHjr4WANVFdvuuJBarX9LdOAl3NQeZQOcS17lRcL+LfQyB8DX2F/jIx2Z1JuKYOKNvO DcXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=4Ah8rZ10cqU0d8QvWlqhIes1F3QIDWNRMHLAV19gJRk=; b=GFLxyPesPRpma1aqW0TLx8qgrI6PBal2jElZx0ODFb0G1LcgXmzbjrOOKJfKszoBKs wBCFWTLe7HNN/+0yElwI3fSbKeTqzFCMAXBJwQjLcLLGSwD0VdO+uzNs3yyQrSrcl9Kp f/NmXl7tq3sexpqVAkB1HemWNZk/VZwNDkVJ5bmXk5tIDpaeWp1onFZH83SdA6aAvdqJ 4HN4AgE9CehpKCyWwpwDHpCTbRW67P0KNIfOcJY0O3GRChgF1PgeEEBIl+2oS7vBjF49 C17JtvobHZlR93Kw+zuDcPkXOtVQ0FLEIbHH7/tMZKmQvvL1wGf4Oz0UA4JnDBgAd5Rw LnMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a125si9752910pgc.79.2017.07.26.06.38.33; Wed, 26 Jul 2017 06:38:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751719AbdGZNib (ORCPT + 26 others); 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 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MPXsH-1dWDdv0bpZ-004lm7; Wed, 26 Jul 2017 15:38:06 +0200 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 Precedence: bulk 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(-) -- 2.9.0 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); \ })