From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.9 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,UNPARSEABLE_RELAY, USER_AGENT_SANE_1 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 8FDF2C433B4 for ; Fri, 14 May 2021 05:41:13 +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 EFC19613F6 for ; Fri, 14 May 2021 05:41:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EFC19613F6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.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:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mTdWQJXdQmCPQD1VP+bZyn7nSFw1HKDIVqxW9vv43+w=; b=X71R43plTnQXTnqxuIBwSVAiJ KL8PA1dycsWuLiCrh+hbY6rWRI5bBZp7CF5vhg1Z+chF+qJ1DCLGeWmdxhUbIJ+WHiF5wJK8V/Gk6 fo1i44zxMLJTpviykH2E7iJWZimqGJw+N8jjQBzTWoJsw1+Vb39rsxt+W0vlaLDMkNJfd43hBTrh4 tTYIxbdFcdwbxmiV3t974FIY6Stc/yxhYssxO1m+mKIV3GqKSu5lY3V85EJu8B07lSwUKTLxNdxlc CLEd5HD+82k7ZUAReKP+4YtVB9YGH94QtUrpkULaB3HDm6JIYEbEVsPh7l7vgS/NZlydR/ihp8DIn MCdzxmceA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhQXL-007ETl-MA; Fri, 14 May 2021 05:38:59 +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 1lhQXD-007ESx-CF for linux-arm-kernel@desiato.infradead.org; Fri, 14 May 2021 05:38:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=U4WmGOoHEOZyxtBGaQ7iAVlEntFbwFTELaSYsOVR8BE=; b=wVHSLa4hmRzA7LuHC0NraDr9dV I6ASSZpZWjBC/BO7p3ZM6zsM9SKBDjEA4s/SBUh5ZU2W97TfgIIJ3dxToiAHepdhoUIoQsiaeMRzC +8JclsrwYtYBSSpFLh+kPcQjwLvOL9ZQ2SOI5c3W+fyzz04+olnEby5BRRiaaZ/AFcFHrPqVrIOks Cffv4Bm+QxhftCIfkWhDLxh2AguZyjCESBGcA8xmRNG6G62G9SBSAcFakWLZF2yQ3vcKSw6UyGE2E zZ/x+UYMLWiJMY8g3doqbPs4whPRBUi51SM+lfVIIIn4JZXEzGzqioUEsfGAEP89R/67owi8Y2E2V pDx8JWZQ==; Received: from aserp2130.oracle.com ([141.146.126.79]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhQXA-00BjMF-Ga for linux-arm-kernel@lists.infradead.org; Fri, 14 May 2021 05:38:49 +0000 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14E5Yv5f024442; Fri, 14 May 2021 05:38:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2020-01-29; bh=U4WmGOoHEOZyxtBGaQ7iAVlEntFbwFTELaSYsOVR8BE=; b=wBj1Nl6WhOV5v6S+rPLaiMnOdVhnGkKPSua1IOkScHpieXxp2mTtX8+GJGbX7B0TIAq4 U2Ye0a3G3oQiazD8sr3ZE75G0wfJydKTSDbOd09rmSxxATB/fWTkVhK8JsGMCGR4+P+p O5f+cI1PVGPcBxaXsmGnlcwFeyUiFLlCQx/QfSSspRskVGELdTZFLhoYPxPquF9Y6ZN3 oJp+8ba969aNgQQkX6AXrcCAbYOj8/rFsg+YkhNWk7fkIvtehO4E8kLArCNrEVfKKyEb hxuSFJdtBqe9GSAdIxCtYIoyUXcTBpJsch1E5P/kPcj2ezEQXSqvDWnkIbBB6cw1eF8p 1g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 38gpnekd61-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 May 2021 05:38:27 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14E5Tnbo188411; Fri, 14 May 2021 05:38:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3030.oracle.com with ESMTP id 38gpq2rpw9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 May 2021 05:38:26 +0000 Received: from userp3030.oracle.com (userp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 14E5cPGD002297; Fri, 14 May 2021 05:38:25 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 38gpq2rpvq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 May 2021 05:38:25 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 14E5cI2p027480; Fri, 14 May 2021 05:38:18 GMT Received: from kadam (/102.36.221.92) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 13 May 2021 22:38:16 -0700 Date: Fri, 14 May 2021 08:37:54 +0300 From: Dan Carpenter To: Colin King Cc: Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] gpio: xilinx: Fix potential integer overflow on shift of a u32 int Message-ID: <20210514053754.GZ1955@kadam> References: <20210513085227.54392-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210513085227.54392-1-colin.king@canonical.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-GUID: aq9JcMCzhOS1vHkJe9ZQMHGnxm2a3Aca X-Proofpoint-ORIG-GUID: aq9JcMCzhOS1vHkJe9ZQMHGnxm2a3Aca X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9983 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 phishscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 priorityscore=1501 clxscore=1011 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105140038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210513_223848_670381_04931AAD X-CRM114-Status: GOOD ( 22.79 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, May 13, 2021 at 09:52:27AM +0100, Colin King wrote: > 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; Doing a shift by BIT(5) is super weird. It looks like a double shift bug and should probably trigger a static checker warning. It's like when people do BIT(BIT(5)). It would be more readable to write it as: int shift = (bit % BITS_PER_LONG) ? 32 : 0; regards, dan carpenter _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel