From patchwork Thu May 13 08:52:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 12255379 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67BAAC433ED for ; Thu, 13 May 2021 08:55:00 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 073CE613D3 for ; Thu, 13 May 2021 08:54:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 073CE613D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=sNwdgRCh3cd6GW3w+iVTj3KKnVnshOUo1AFX88shFS0=; b=P1S9+YLLxvUnvfxBFEw1SRt9FF /8NxjO1EZqdsp4gCJRWOe5UA+ynWDinPWDrzxkk4s9zTiyc1d9T8oq4iUMXFaBkRFUOBLv663a64b UOD1MS4Q2tZkGsiFHTAj4Lj8/jjRw5a3djXpa0wezLmnd7XT0K3Ynz0qgLFxYe82G9DVZQoyfAlqR K4wusTcwB9kfkZi7RMGoefHHs2ZLQz75sW22so1jzRxBlMHyku/hzjlVWZTh3gOwitpnEyAQqHitd TiCTxeuVArzUuRu+yhiqUXbANLYmjNJ3KLJmL6pJleqw34L/sRBOkjnI40qAk7I/PhS3stPnHtGrZ 5PC7lSwQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lh75F-005Bgy-Dk; Thu, 13 May 2021 08:52:42 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lh75D-005Bgp-Fl for linux-arm-kernel@desiato.infradead.org; Thu, 13 May 2021 08:52:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:In-Reply-To:References; bh=M8TUgP/LDbdOIRNvBmzNzCczVpySPzIjHkiRtk5T6Js=; b=0Pv0v53C8U1/NJ9ASrfUqrVWB7 iZsHx6rPqPAC0/R1ZNO4tYZ0NynhrE/qMV7vKCERvuBfoSgE4I/f9DdlwqByMCbu4KzzZb0BOlaWn DXtoDi3FBBC6ru8o73dfaDvLSy8iIJgitPKpXwPUkZldlQkRMVQNTbFF63vRIoTa/wuhp2bro8g7x 5MNfiTnYBVITpd7cy60Ns4/Kf70dY+yubiTd5/5IgJw1qI/X71uTGTda9Lu7ZXhVTfkeBtKEiDIPd sUx0pVyM0L03dfRCHSlb+BfN1l0ztDwXtuapOwVbD3JHqIfmMd/A0WwFMQLPJw9r7zaNPL66B4hi+ UT8nraOA==; Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lh75A-00B7A3-2p for linux-arm-kernel@lists.infradead.org; Thu, 13 May 2021 08:52:37 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lh751-0006fu-U5; Thu, 13 May 2021 08:52:28 +0000 From: Colin King To: Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] gpio: xilinx: Fix potential integer overflow on shift of a u32 int Date: Thu, 13 May 2021 09:52:27 +0100 Message-Id: <20210513085227.54392-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210513_015236_144586_DAA721B9 X-CRM114-Status: UNSURE ( 9.85 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Colin Ian King The left shift of the u32 integer v is evaluated using 32 bit arithmetic and then assigned to a u64 integer. There are cases where v will currently overflow on the shift. Avoid this by casting it to unsigned long (same type as map[]) before shifting it. Addresses-Coverity: ("Unintentional integer overflow") Fixes: 02b3f84d9080 ("gpio: xilinx: Switch to use bitmap APIs") Signed-off-by: Colin Ian King --- drivers/gpio/gpio-xilinx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index 109b32104867..164a3a5a9393 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -99,7 +99,7 @@ static inline void xgpio_set_value32(unsigned long *map, int bit, u32 v) const unsigned long offset = (bit % BITS_PER_LONG) & BIT(5); map[index] &= ~(0xFFFFFFFFul << offset); - map[index] |= v << offset; + map[index] |= (unsigned long)v << offset; } static inline int xgpio_regoffset(struct xgpio_instance *chip, int ch)