From patchwork Thu Mar 7 12:09:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 159845 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7355733jad; Thu, 7 Mar 2019 04:10:15 -0800 (PST) X-Google-Smtp-Source: APXvYqyexqaEPvfybmsAjxlbdCmCmpD5Amc65TASNW7pAo/PZon3ZOJniwppV/pROUO53HOpMcwg X-Received: by 2002:aa7:930b:: with SMTP id 11mr12523730pfj.49.1551960615608; Thu, 07 Mar 2019 04:10:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551960615; cv=none; d=google.com; s=arc-20160816; b=jTZ45bS+rcX9hDXaMtcH0gLhXGNXl2hbQ2PvXoxYG30YB5l0UXO0SYs8+eacKVyZRW LkVkiCpan0u+TN/8VpXl48WBDHs2oqd1lxn+b+aQ44mk6swi1FGldPYsGzipK6CpdFE8 l3nbJ9fG4ULDK6jZ87oxDowF8x1KDHT9bh3Vtni+r4bbAGs/uNgPVxsfIiI0aD36x/lr nLCiPpdGScUKV478qaHgC7VGfTQ2casNQp4dqPAhqiMY2/4fxJ3gN+hwuvK+SGJPWEs/ Y5/PD1bIcknG6iRr5s0goYrrv2jNATGJ/vOgzi2IcRLsq0sLqpZkTR8gpvMo/ewnFI8M V7YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=OnhPd9INW+YCK3J4L6vfGgPETeQRaqRQ1lxcrQTFZPE=; b=y4/ClQjAkhDs233/lMULzHbaofXWnCMlKMO3tdQEQK5ZZJEBFCxZMtbskN120B8/6d s5oNgkYl3Zq8FH47P4oWP443kOIuB6jSYAmyQUM9zOtFISaG6G84v0jj5P2ZN/Dn3VO2 htWnNvP/TrZxKGELzUZRE30bk4/NhtvCJuhp6WO5gIFqmLc5wX12rsHgv8je0WCIfaA9 /ZtYtDjiAT97SJo8DRbNbIDWHNpbKsuSmf9WxmXEHASeuDT6lTfrBr1yfnz8x+QT9jDc VY1bXbF41Sxb4oaRf0kssySxB6HZMwEQ4ygu84pcJj5hsA0QvaUG9daeOfa39IqZhUti 1JPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-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 v79si4190181pfa.207.2019.03.07.04.10.15; Thu, 07 Mar 2019 04:10:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-spi-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-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726166AbfCGMKP (ORCPT + 1 other); Thu, 7 Mar 2019 07:10:15 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:54663 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726101AbfCGMKO (ORCPT ); Thu, 7 Mar 2019 07:10:14 -0500 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1M1YpJ-1h4Kgg2Y2N-0033Ye; Thu, 07 Mar 2019 13:10:05 +0100 From: Arnd Bergmann To: Mark Brown Cc: Nick Desaulniers , Geert Uytterhoeven , Arnd Bergmann , Boris Brezillon , Marco Felsch , Linus Walleij , Frieder Schrempf , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] spi: work around clang bug in SPI_BPW_RANGE_MASK() Date: Thu, 7 Mar 2019 13:09:46 +0100 Message-Id: <20190307121004.1068172-1-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:C+Y06PKXuxT+51gK/T75WIVIzS/YmSjK3h6DTpL2Ufat49CCNTU QBhknMDjavxmXvdSismG2+YwTZpvqIogux6Yg15PGcR5vcO+ki8S/lau+4lx8hQJL8en4cw znTl0N6w2YxEAUoFt4dZ854GbpXGlREkebBQk0ik9bDzwpt5CPZlG7V+0+NykJWW33IN/3j nsAx5xZJ9kyy8758JPWHg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:QwT8fHCGlMo=:ZfG71IUUYpKua44RdT6BJB Bqe8W6Ov2O+jI3PTiYTmaaAFaoENZxSNnRI5EAENTveokD4BhlIKiD9vPzM30lVx3pbY1U7r1 Wisbk1+CgNPaGxSXgDYg4cUJvo5c8b5bqPGnC4UlJnB8YcLMcRsrOrG3+qKGgzVTeZLuCvNjA qOvGUBUw8nL6RxNRxq9AkN1TgYLvbKbz/wtApsUES7BW5GGgo0L5V4U/WLeVNZgJdvsFPxJqc 3HhqZpxJwlVFj68tdy3gm7/VFeHQ0TeAFOgS6PtgtYq7o6315I+tLtSTxYshBTmwl+M7EMPaw VvTcqGgTIuXb6C7QFqpKkZsHz7mLehkxGPRIGqw8rM36Kf7WprCtyuMFTBrsxH3cozL9udOcC ypuXD3ZBtHht79yCOw5HmpQlSTh59WWtZNdU9djI1PXDtnjHhC4gTl4c2Fzvw8EhG+n54RTJ8 91eoQsg27a7Pp9344kO9vzvsm3XgcQSn7/EQlOigK73g7BpEdzt+BR5SV8fAn3Eog0eXGFBSW 0bOrCBQn5skp4yaWsgyvoNnpBBcnbGD8TSaF7LorzjALe+SSVUGh2opb9KLiM+6oTv7Cw0gUi 01kNLd0HAibVVP1dyBmAzlH6JxpqYnfQ/FBedgufasU3uVNKhNPIIUotdHhRcJqORGgjFq4HL Z3AUQ3OZORc9j+KPySGYIGj2C+uhoDl0bW0sr9VgtN7ibZK+G2fHzcXF6aOlvpLcFCrHv5Is+ 4Z23O4vcTxA545byLjdKuplGqSkrJvNSRYBcRQ== Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Clang-8 evaluates both sides of a ?: expression to check for valid arithmetic even in the side that is never taken. This results in a build warning: drivers/spi/spi-sh-msiof.c:1052:24: error: shift count >= width of type [-Werror,-Wshift-count-overflow] .bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32), ^~~~~~~~~~~~~~~~~~~~~~~~~ Change it to shift one less than we want, and then shift one more bit afterwards. This should give the correct result for all valid input, since it has to be in the range 1..32 anyway. Link: https://bugs.llvm.org/show_bug.cgi?id=38789 Signed-off-by: Arnd Bergmann --- v2: add a code comment --- include/linux/spi/spi.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.20.0 diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 662b336aa2e4..1500745a9835 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -444,8 +444,12 @@ struct spi_controller { /* bitmask of supported bits_per_word for transfers */ u32 bits_per_word_mask; #define SPI_BPW_MASK(bits) BIT((bits) - 1) -#define SPI_BIT_MASK(bits) (((bits) == 32) ? ~0U : (BIT(bits) - 1)) -#define SPI_BPW_RANGE_MASK(min, max) (SPI_BIT_MASK(max) - SPI_BIT_MASK(min - 1)) +/* + * double shift to avoid shifting beyond BITS_PER_LONG, see also + * https://bugs.llvm.org/show_bug.cgi?id=38789 + */ +#define SPI_BIT_MASK(bits) ((BIT((bits) - 1) << 1) - 1) +#define SPI_BPW_RANGE_MASK(min, max) (SPI_BIT_MASK(max) - (BIT((min) - 1) - 1)) /* limits on transfer speed */ u32 min_speed_hz;