Message ID | 20240301144517.2811370-1-usama.anjum@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-88581-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1126725dyb; Fri, 1 Mar 2024 06:46:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUFanq1JlqdsbpFSyjEGMcIoNu3SeLkQT+8ZGb+LsT0vr3ejLMVjha88vDNCyixMtBYrz8ilxNCKUXN/yz20IXkhhmJSQ== X-Google-Smtp-Source: AGHT+IG10CeXxc88c3PYWl3ykOUHDz35vX8B8rrw9pRKsCRsBEn4VbqM3cDql3zBxiuV136vWPLc X-Received: by 2002:a17:906:791:b0:a44:93de:f4bb with SMTP id l17-20020a170906079100b00a4493def4bbmr1379870ejc.28.1709304390381; Fri, 01 Mar 2024 06:46:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709304390; cv=pass; d=google.com; s=arc-20160816; b=CxlcjCNWtDxjmzBpIq1NsHTpg1Wn0PyAL5XRa4pK5iE/OEPiBwI4+4/YP/RlKD7IjR G1sUuM56K04/f8WiBz2DdASEZuDQLqONfkpys4FNNXeZAL9iyevmErAdk2dJUGb1O+bq O3d5FTe0CwNjFke2j4DYHXpZV0WvrXNu85Zdbki9MpDPYjsESYDFZdhkPPPS1UqgBX0L Ep+62sx+01yFlr8Rk7jbz7kbdKRBq36KwtUvaq2iKcj62MzEntXhq0FkqwYP4z2rzta5 rm+NzDKCTRcL2+v8OzakDb9acPjzFiEujyu40duoFKxx4BTiOJ2Wq+uvn2DKHJ7bidTu gecA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=5XrDubaNLoXexWseEyyU5IrWlisLUPHShfAxwRkaWE4=; fh=xrRzzZKDe3pD03Ov6NLG3+bUKM/9Lzz0w05ooeW3rqo=; b=xpLUaUpFgSAWAtUKQP3bVuCrAumR03dEPNe2s9zP7QUj1E2p0LM4pml9IFhkuC0Q+k dldTnWWSgY7fg7LnNI7bzeonedB8UoLk/6W2/HziKlI7oG8o9uhub/aY7izYODOUX12s p53bnnnmphKiNFX0U+GyKwfoSuE3EiE4aMGnSavpH8qf97qiqIWcbf7rzfK6NMDWJthh FG/keAlE5NOqA1B+hanagA5i5jj0WFERFV9D3/Eoiyx/+kQPNmzzyc1TXbc0ZmlplEjy Fas6vICHSBBPsOfpHmqaKWDcHyN2atwfjPrcrNRdw82BY8iGVVq5vtqBDMc7OSFbwCzF H6qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=pZkNualV; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-88581-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88581-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f15-20020a170906494f00b00a449f94c9f6si341432ejt.95.2024.03.01.06.46.30 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 06:46:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88581-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=pZkNualV; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-88581-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88581-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 04A2A1F24F01 for <ouuuleilei@gmail.com>; Fri, 1 Mar 2024 14:46:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B85906EB69; Fri, 1 Mar 2024 14:45:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="pZkNualV" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 943EF6E2BD; Fri, 1 Mar 2024 14:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709304300; cv=none; b=MmSkZsWn3lv5NjIM053aXJTdbHTxd0QVqCDrKeSdgD4WAoqYmxai7LgjjgrZ1PIMpidBTm03YE0lRktwfxmMez0VI9PjVR4zMoXS1reZqzJu17HClkXEPX9YLmSTUnF/MeJfGD7lvPAIWHbGYLS+62skm9jPnEsUNgWA4XF7AZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709304300; c=relaxed/simple; bh=+HDNwzccRkcc9hkZwYDAOt4M5Q55mu65xiChlYxn1dQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=WJNqQEXHa2QsUIJd/Dw49NYFmBhrkT9mueREE4Nc3+0i3soV4IQmKqh/Wu/fQIWtQ/J2zt8klO0hFU9Lo+2k6XqQCeTdwypv7xN7PzgVHbYiyZ4jnTuh+8OMpL1R6wER6JXJWtfWsSd81FJL3aUH1Ll4mEEymMCO4W/xSh4XVPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=pZkNualV; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709304297; bh=+HDNwzccRkcc9hkZwYDAOt4M5Q55mu65xiChlYxn1dQ=; h=From:To:Cc:Subject:Date:From; b=pZkNualVekd3oqnVTbyHho7X9a0TfTXMrnaziDRaJuNjpVhtH/ldHxYvBFfjVKGs8 nRTXZokimaEUyf8L/HDeFwqHyiNNDD9SIny/tWWzrFRWqi0eCd/z4kTHb5LZLovYv/ la1r0v6NgLzIg89PPK8lXJi1Qx/K6rfOnIeB5Dp/REZmZ/rbTHybVUX7/cGS6Mn+DR t8AZo93TmYzPzeYWEfeqslFe+xWaf0d2DVURdIUGlY1eMAGAsCWbbYstJ6/RNW42uQ 5XiSJwzhVx4YxHieVKiny3fIds9b51FFRHQnNrAwIdpBlATEOXNCNUYJJTJnU7n6Gr 0PSx8sSrce0XA== Received: from localhost.localdomain (broslavsky.collaboradmins.com [68.183.210.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id EA57137803EE; Fri, 1 Mar 2024 14:44:53 +0000 (UTC) From: Muhammad Usama Anjum <usama.anjum@collabora.com> To: Tudor Ambarus <tudor.ambarus@linaro.org>, Pratyush Yadav <pratyush@kernel.org>, Michael Walle <mwalle@kernel.org>, Miquel Raynal <miquel.raynal@bootlin.com>, Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com>, Takahiro Kuwano <Takahiro.Kuwano@infineon.com> Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>, kernel@collabora.com, kernel-janitors@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] mtd: spi-nor: core: correct type of i to be signed Date: Fri, 1 Mar 2024 19:45:16 +0500 Message-Id: <20240301144517.2811370-1-usama.anjum@collabora.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792335560599137213 X-GMAIL-MSGID: 1792335560599137213 |
Series |
mtd: spi-nor: core: correct type of i to be signed
|
|
Commit Message
Muhammad Usama Anjum
March 1, 2024, 2:45 p.m. UTC
The i should be signed to find out the end of the loop. Otherwise,
i >= 0 is always true and loop becomes infinite.
Fixes: 6a9eda34418f ("mtd: spi-nor: core: set mtd->eraseregions for non-uniform erase map")
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
drivers/mtd/spi-nor/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi, On Fri Mar 1, 2024 at 3:45 PM CET, Muhammad Usama Anjum wrote: > The i should be signed to find out the end of the loop. Otherwise, > i >= 0 is always true and loop becomes infinite. > > Fixes: 6a9eda34418f ("mtd: spi-nor: core: set mtd->eraseregions for non-uniform erase map") > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> > --- > drivers/mtd/spi-nor/core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c > index 65b32ea59afc6..46bc45b80883f 100644 > --- a/drivers/mtd/spi-nor/core.c > +++ b/drivers/mtd/spi-nor/core.c > @@ -3373,7 +3373,7 @@ static u32 > spi_nor_get_region_erasesize(const struct spi_nor_erase_region *region, > const struct spi_nor_erase_type *erase_type) > { > - u8 i; > + s8 i; Can we just have an "int" here. So we don't shoot ourselves in the foot again. I'm really no friend of these kind of micro optimizations, it should have been int in the first place IMHO. -michael > > if (region->overlaid) > return region->size;
On Fri, Mar 01, 2024 at 07:45:16PM +0500, Muhammad Usama Anjum wrote: > The i should be signed to find out the end of the loop. Otherwise, > i >= 0 is always true and loop becomes infinite. > > Fixes: 6a9eda34418f ("mtd: spi-nor: core: set mtd->eraseregions for non-uniform erase map") > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> > --- > drivers/mtd/spi-nor/core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c > index 65b32ea59afc6..46bc45b80883f 100644 > --- a/drivers/mtd/spi-nor/core.c > +++ b/drivers/mtd/spi-nor/core.c > @@ -3373,7 +3373,7 @@ static u32 > spi_nor_get_region_erasesize(const struct spi_nor_erase_region *region, > const struct spi_nor_erase_type *erase_type) > { > - u8 i; > + s8 i; I have a patch in my output which also addresses this bug but you beat me to the punch. Declaring iterators as "u8 i;" is a canonical bug. https://staticthinking.wordpress.com/2022/06/01/unsigned-int-i-is-stupid/ regards, dan carpenter
On 3/1/24 15:04, Michael Walle wrote: > Hi, > > On Fri Mar 1, 2024 at 3:45 PM CET, Muhammad Usama Anjum wrote: >> The i should be signed to find out the end of the loop. Otherwise, >> i >= 0 is always true and loop becomes infinite. >> >> Fixes: 6a9eda34418f ("mtd: spi-nor: core: set mtd->eraseregions for non-uniform erase map") >> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> >> --- >> drivers/mtd/spi-nor/core.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c >> index 65b32ea59afc6..46bc45b80883f 100644 >> --- a/drivers/mtd/spi-nor/core.c >> +++ b/drivers/mtd/spi-nor/core.c >> @@ -3373,7 +3373,7 @@ static u32 >> spi_nor_get_region_erasesize(const struct spi_nor_erase_region *region, >> const struct spi_nor_erase_type *erase_type) >> { >> - u8 i; >> + s8 i; > > Can we just have an "int" here. So we don't shoot ourselves in the Muhammad, do you care to resubmit using int? Would be better indeed. > foot again. I'm really no friend of these kind of micro > optimizations, it should have been int in the first place IMHO. > > -michael > >> >> if (region->overlaid) >> return region->size; >
On 3/4/24 12:51 PM, Tudor Ambarus wrote: > > > On 3/1/24 15:04, Michael Walle wrote: >> Hi, >> >> On Fri Mar 1, 2024 at 3:45 PM CET, Muhammad Usama Anjum wrote: >>> The i should be signed to find out the end of the loop. Otherwise, >>> i >= 0 is always true and loop becomes infinite. >>> >>> Fixes: 6a9eda34418f ("mtd: spi-nor: core: set mtd->eraseregions for non-uniform erase map") >>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> >>> --- >>> drivers/mtd/spi-nor/core.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c >>> index 65b32ea59afc6..46bc45b80883f 100644 >>> --- a/drivers/mtd/spi-nor/core.c >>> +++ b/drivers/mtd/spi-nor/core.c >>> @@ -3373,7 +3373,7 @@ static u32 >>> spi_nor_get_region_erasesize(const struct spi_nor_erase_region *region, >>> const struct spi_nor_erase_type *erase_type) >>> { >>> - u8 i; >>> + s8 i; >> >> Can we just have an "int" here. So we don't shoot ourselves in the > > Muhammad, do you care to resubmit using int? Would be better indeed. I'm sending a v2 with int. > >> foot again. I'm really no friend of these kind of micro >> optimizations, it should have been int in the first place IMHO. >> >> -michael >> >>> >>> if (region->overlaid) >>> return region->size; >> >
On 3/4/24 08:46, Muhammad Usama Anjum wrote: > On 3/4/24 12:51 PM, Tudor Ambarus wrote: >> >> >> On 3/1/24 15:04, Michael Walle wrote: >>> Hi, >>> >>> On Fri Mar 1, 2024 at 3:45 PM CET, Muhammad Usama Anjum wrote: >>>> The i should be signed to find out the end of the loop. Otherwise, >>>> i >= 0 is always true and loop becomes infinite. >>>> >>>> Fixes: 6a9eda34418f ("mtd: spi-nor: core: set mtd->eraseregions for non-uniform erase map") >>>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> >>>> --- >>>> drivers/mtd/spi-nor/core.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c >>>> index 65b32ea59afc6..46bc45b80883f 100644 >>>> --- a/drivers/mtd/spi-nor/core.c >>>> +++ b/drivers/mtd/spi-nor/core.c >>>> @@ -3373,7 +3373,7 @@ static u32 >>>> spi_nor_get_region_erasesize(const struct spi_nor_erase_region *region, >>>> const struct spi_nor_erase_type *erase_type) >>>> { >>>> - u8 i; >>>> + s8 i; >>> >>> Can we just have an "int" here. So we don't shoot ourselves in the >> >> Muhammad, do you care to resubmit using int? Would be better indeed. > I'm sending a v2 with int. thanks!
Il 01/03/24 15:45, Muhammad Usama Anjum ha scritto: > The i should be signed to find out the end of the loop. Otherwise, > i >= 0 is always true and loop becomes infinite. > > Fixes: 6a9eda34418f ("mtd: spi-nor: core: set mtd->eraseregions for non-uniform erase map") > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 65b32ea59afc6..46bc45b80883f 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -3373,7 +3373,7 @@ static u32 spi_nor_get_region_erasesize(const struct spi_nor_erase_region *region, const struct spi_nor_erase_type *erase_type) { - u8 i; + s8 i; if (region->overlaid) return region->size;