From patchwork Fri Oct 13 12:12:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 115766 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp658872qgn; Fri, 13 Oct 2017 05:14:06 -0700 (PDT) X-Google-Smtp-Source: AOwi7QB+mGtPksGWeo2tPacX/8M5K+MeCA8tQYgi8MA2nEPu5CIY3Mo5HpQTQFVyL3dD4nt1ARE5 X-Received: by 10.84.195.1 with SMTP id i1mr1242953pld.70.1507896845914; Fri, 13 Oct 2017 05:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507896845; cv=none; d=google.com; s=arc-20160816; b=scdfSOk6Bdk7LedV/ZsqICzaSViWPSxCgCa4bOUD3HIa1bBZ9WLVQzlRDGoi+ubWZH JFkjg7CgLT38yyqHNr8A9iy6T39WttVR32mFKIFdFlUruCnI9K7agY7tlAdstP9pe7rF cyyb2miVl8MVc1VgisXgCKOmIbCRvT3l5X9IXE9c/OJz4DWvlqa7joTAX5ynFbUyaych WiW1PXPgdNzIKnAom3J1nQYGdQagbXtV+twn1RFATVKCGwlPQ/b1s09brrDSWPKQUFlN DfmTNIdfjNtYbpiEpeue0I+zgERW4smOLKsAm4VC+3wdedeyoT5vSn8OwFP7D/ZpRcqq 5u1w== 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=PznYo40rtBdqZujY2WYtMhoue1JCS7zJOEgUdY8aLt0=; b=mE6tGIIHFkZOd90gv+bXtR63IYWGBqhB83Wv1BmuH9NhTGw73serEDCCPFBiDL6oGF 4OAZ/ffQf5DypDsz0HJw4Wws3knY0Wb8qr5GqGmgRsg8RrYljEtMgbWn6AEdUYI36r4L pgG5Q3ChMgeOBDyxCXFqLoyGR6R+mwvP5olMRZRZHZvPCI+SIxJ2dT+f3/TEbi+utq1D Xj76kw+VMxebWf+k/LaLtF6pg0wfRT1tD4I4iCbhiQJXjxIDseOpU0iQxIaE2Y3FlJZ/ DIP2mGx0GD7dRTrn2tV/sxK21XczmmOOLE5yCIiMD6Lri9wbs7utEYQk6OLTPIu1nYhl sagw== 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 l3si560355pld.337.2017.10.13.05.14.05; Fri, 13 Oct 2017 05:14:05 -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 S1758056AbdJMMOD (ORCPT + 27 others); Fri, 13 Oct 2017 08:14:03 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:50893 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753258AbdJMMOC (ORCPT ); Fri, 13 Oct 2017 08:14:02 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue006 [212.227.15.129]) with ESMTPA (Nemesis) id 0LiJtA-1dWvoI3FMK-00cen3; Fri, 13 Oct 2017 14:13:34 +0200 From: Arnd Bergmann To: Andrew Morton , Mark Brown Cc: Arnd Bergmann , Charles Keepax , Michael Grzeschik , Chen-Yu Tsai , Masahiro Yamada , Ramesh Shanmugasundaram , "Alex A. Mihaylov" , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] [v2] regmap: avoid -Wint-in-bool-context warning Date: Fri, 13 Oct 2017 14:12:45 +0200 Message-Id: <20171013121313.195037-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:wp3FdoNyhNw4yBFSwoU8tIrwDtA7GQXnpvxON0ZuoeebJudT16N xU5IeEhd6O5tyUUMHiJZnXkEtZIQjiqOvBXY5X+OskDwV1vcBtaTyMEUJ6ev7LWxDTArbi6 YUV19bm5cNOIbkkI9+0xNYJ3+R6ijvli9cV3mgAP9OdmRkoGrG++tuAYcwCZX08kkk49Ujj I1XsWNC6n189vnwCYZA6w== X-UI-Out-Filterresults: notjunk:1; V01:K0:T2/Q2XJgV1c=:9cJurZflW5UEv/zcIGSH6M pZr0g/oou2cVW2Zn1YzGDvIeq4EKhb/EljowfFQUjvTV6QmiDPo2im20yBLaDnFsR1O6Co+ge kc89BRHXMmd+0dR5TzC2TuWiZOmN0QzF7Jf+qSp9H2RLd6nZ1b1NgrMTItbLoiC5tYV8gt98J z/CMyKyyvWiPn9zo96FtGe1oLdpnfhUoyJhc3n5OnN0jFmMhJsi5EkhkLsQdGtNdKZJyPzGUy +yvSTZQ9jxSI+HZA5WlwwbbKgCulPmVxpu0wi4BAbDlZuej0dzzLWOch1bEE4saIuQAJQZMoL JXJ7e23bJME7jdDXvCXHG2IYtwS4mdCFFpbKvZX80GD7jEuE2FqKIk9YYIenTQD/PFy4hX00k jfJ+mzkK9IA3qBhU5trHKhLUhRHZyFndGfb5ekqG2UMuuuDHk+1FXijwJzVwwy6NtoGQ3FUzp YQ7zJjGjGCBvPZzyQZMJUg8TVar83+YMS/y9D6LikhfFBFQEoUimoatn5ag+WC9uvGmWlEj/i 5ufW60JDdGWYMuzuWQldSLf1gXlYbkowuz9jOuHDHo2CbRorUn2lDEgul17L97xUqGWaWkXUs HmbxqmJhWMsYTjyZctom7WClKwjrJYrOX7cFktYfDCDjRSSZdbX0KwQ4+57qIJ12OD3qIWU3f brJ2uVJ07UCIBURN49SEvMoxdt1QkJdBNH3a/MXinZ4c7sVXMR7Np0ylLh8BdmDgcayIMSSRs qKAnAHOI6eDlFfHvOfAuVKz4fqCiVhs98cJUDEu69qGfwlmzy/odqKZzAeAQbnpHdqB4bYDHF pfGu79A 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 regmap 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 Signed-off-by: Arnd Bergmann --- v2: rebased on top of the latest regmap tree, which contains a second function with the same problems, and split out from the change in iopoll.h --- include/linux/regmap.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) -- 2.9.0 diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 1e369f0e921d..edad98890b9b 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); \ }) @@ -160,21 +162,23 @@ struct reg_sequence { */ #define regmap_field_read_poll_timeout(field, 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 pollret; \ - might_sleep_if(sleep_us); \ + might_sleep_if(__sleep_us); \ for (;;) { \ pollret = regmap_field_read((field), &(val)); \ if (pollret) \ break; \ if (cond) \ break; \ - if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \ + if (__timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \ pollret = regmap_field_read((field), &(val)); \ break; \ } \ - if (sleep_us) \ - usleep_range((sleep_us >> 2) + 1, sleep_us); \ + if (__sleep_us) \ + usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ } \ pollret ?: ((cond) ? 0 : -ETIMEDOUT); \ })