Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2ABCACFC267 for ; Fri, 21 Nov 2025 11:56:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=aVSZbQD502smkMfaHifOlLvBRJFKFzJDkcujux/nbgo=; b=Nb0Ss65zuZmskZ bU2WKL2qUtWvIyT9j4ZMv2SPgHWx2qIeuO7BE/icun2HU5e9X4Jcc9QE3NArF11G430xNH4UpsizM oT9QVrIx0d2PT3njCNb5mb/zoAnDGvYsClQ8nCrsCgRZhdmT2ZWgM/hye/t/6SUR8eX4gtM3S5V1J fY/dTBZFeCzZ/SdRI9kyBVjEs6i8/uNmQUGSAUc21+sOQsEGQZqSz1Zq9rIrd1YFcRsIfdRtIUUXl pTXt5HktMPylNZ1k0w4HziyHkuQsHq5V4pJK5O2T+C6gq5CN2terdG+bfrfKOcOMFotbtW2OdKELw RvRLmYSE1sa6Zm6S32DQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vMPkO-00000008KrK-0vzr; Fri, 21 Nov 2025 11:56:16 +0000 Received: from forward101b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:d101]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vMPkI-00000008Kqi-492P for linux-mtd@lists.infradead.org; Fri, 21 Nov 2025 11:56:13 +0000 Received: from mail-nwsmtp-smtp-production-main-74.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-74.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9098:0:640:59a5:0]) by forward101b.mail.yandex.net (Yandex) with ESMTPS id 275C1C00EB; Fri, 21 Nov 2025 14:56:00 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-74.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id btWHGr5L4qM0-yTEoVw2u; Fri, 21 Nov 2025 14:55:59 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itb.spb.ru; s=mail; t=1763726159; bh=72tZMXMbrGt2bxxBvi56/JVoucyj7GYZJLxapjYCMeo=; h=Message-Id:Date:Cc:Subject:To:From; b=VchB+89NOixxgNbVYuL3ui9ZJ0HlUfxZgyofm27R3EYy/E7fAzvq6bvRnEM0AI+Ju 4tEY8WYBrUY8tkV8cZ4O14YCWrNpyKtninEgzKnFDZ28pswM4zJ4hwuoHOrXxJK7t8 hy68Odfb6mYIzU3T+4zmMk1PBtH+Bn0UJdiqVdRI= Authentication-Results: mail-nwsmtp-smtp-production-main-74.iva.yp-c.yandex.net; dkim=pass header.i=@itb.spb.ru From: Ivan Stepchenko To: Miquel Raynal Cc: Ivan Stepchenko , Richard Weinberger , Vignesh Raghavendra , David Woodhouse , Jared Hulbert , Alexey Korolev , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.com Subject: [PATCH] mtd: lpddr_cmds: fix signed shifts in lpddr_cmds Date: Fri, 21 Nov 2025 14:54:46 +0300 Message-Id: <20251121115446.11421-1-sid@itb.spb.ru> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251121_035611_584204_A76FA766 X-CRM114-Status: GOOD ( 12.79 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org There are several places where a value of type 'int' is shifted by lpddr->chipshift. lpddr->chipshift is derived from QINFO geometry and might reach 31 when QINFO reports a 2 GiB size - the maximum supported by LPDDR(1) compliant chips. This may cause unexpected sign-extensions when casting the integer value to the type of 'unsigned long'. Use '1UL << lpddr->chipshift' and cast 'j' to unsigned long before shifting so the computation is performed at the destination width. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: c68264711ca6 ("[MTD] LPDDR Command set driver") Signed-off-by: Ivan Stepchenko --- drivers/mtd/lpddr/lpddr_cmds.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c index 14e36ae71958..bd76479b90e4 100644 --- a/drivers/mtd/lpddr/lpddr_cmds.c +++ b/drivers/mtd/lpddr/lpddr_cmds.c @@ -79,7 +79,7 @@ struct mtd_info *lpddr_cmdset(struct map_info *map) mutex_init(&shared[i].lock); for (j = 0; j < lpddr->qinfo->HWPartsNum; j++) { *chip = lpddr->chips[i]; - chip->start += j << lpddr->chipshift; + chip->start += (unsigned long)j << lpddr->chipshift; chip->oldstate = chip->state = FL_READY; chip->priv = &shared[i]; /* those should be reset too since @@ -559,7 +559,7 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len, break; if ((len + ofs - 1) >> lpddr->chipshift) - thislen = (1<chipshift) - ofs; + thislen = (1UL << lpddr->chipshift) - ofs; else thislen = len; /* get the chip */ @@ -575,7 +575,7 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len, len -= thislen; ofs = 0; - last_end += 1 << lpddr->chipshift; + last_end += 1UL << lpddr->chipshift; chipnum++; chip = &lpddr->chips[chipnum]; } @@ -601,7 +601,7 @@ static int lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len) break; if ((len + ofs - 1) >> lpddr->chipshift) - thislen = (1<chipshift) - ofs; + thislen = (1UL << lpddr->chipshift) - ofs; else thislen = len; -- 2.39.5 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/