From patchwork Thu Nov 2 11:40:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 117800 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2052057qgn; Thu, 2 Nov 2017 04:41:04 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QHzRvFnkYsWAAvlHGGpDjqJnDHNCQIdldhw0wVw/SOsj/hLcKsq+QhJ0P6qALv8eu1Y6at X-Received: by 10.98.70.147 with SMTP id o19mr3461233pfi.61.1509622864310; Thu, 02 Nov 2017 04:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509622864; cv=none; d=google.com; s=arc-20160816; b=GdlvwJk8YozRR63Nn2WrzmF2wi6KfVTBCATrirf+cejAxSOGv0Zra20rmxDVW8OkvG EtGDkiDYOYnnQ6uZ9aKfFdPop00Klmt6DhO9dCSPUIbSrM/Ni50XryM00+H3CBzPpzVZ QnUaHu5kP0hx0AhO+sCVWvdLhy/k55RdluvNq4Qf3tLEvDO/bpP4D8WHXRQCRoWf0YXq BoNnLhrIOznWywKpmVPZ+gOzedKzR5zjVxrFJvDJE7XFACv5YFNMK695AMFx5plAWBDd JWIPF7aEF9eNhzNrj4HksGF+aF4puAu04U4EX8ELJF8uGC8N1oTgGEmo2ErsuOrxgNWY 6+tw== 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=VqnJGDzUSh6vCMQVIWCJ3TkaQ/mRuKpuFLAXG+7jxtc=; b=XXLtc06NzwbdnQTCvqgItVZf98ixFG1G+8eHiXVWTn856PkZ66HkxemeIUcFtYnIH0 N6hyG/2/c9uqBgwApB3jsKTBhgjOEAf5pOdSjtfTsDz03n9X74EFnyMqSO3/8JmRJSOz KWnde9PaYrUAofPmg/HAdYKtMntgrsLwvjkZ2NgOpn98LgbavSvtc0CyUn/8fh8brxIW LnvkU7Ui1UQyOdeHaFYWyZtM8IDxw3KoVQm5SraWDa9y8T/R4ZDZ1Z4OytHnq9l1SX9H HcSIxwQMNgtVxEj5tltB7ggGtSKRm2CtKqZjeO9eMymjxe3xWT0eJvdhczdO2tn1gbMD PKiQ== 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 h71si3271907pgc.408.2017.11.02.04.41.03; Thu, 02 Nov 2017 04:41:04 -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 S1754205AbdKBLlC (ORCPT + 26 others); Thu, 2 Nov 2017 07:41:02 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:63762 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754131AbdKBLk7 (ORCPT ); Thu, 2 Nov 2017 07:40:59 -0400 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0MHpFN-1e8qxL3P37-003dUh; Thu, 02 Nov 2017 12:40:50 +0100 From: Arnd Bergmann To: Andrew Morton Cc: Arnd Bergmann , Mark Brown , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH] [RESEND] [v2] iopoll: avoid -Wint-in-bool-context warning Date: Thu, 2 Nov 2017 12:40:36 +0100 Message-Id: <20171102114048.1526955-1-arnd@ar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/2cf/OvdBYDaHvyLT2ruoUjyAccPxVhgA== 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 from gcc-7: 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 two 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 Link: http://lkml.kernel.org/r/20170726133756.2161367-1-arnd@arndb.de Reviewed-by: Mark Brown Signed-off-by: Arnd Bergmann --- v2: the v1 patch was in mmotm since I first posted it, but it gained a conflict on the regmap header and got dropped. I've split it in two patches now as Mark originally suggested, only the iopoll patch should need to go through mmotm this time, while Mark has already picked up the other half. --- include/linux/iopoll.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 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; \ })