]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
mtd: lpddr_cmds: fix signed shifts in lpddr_cmds
authorIvan Stepchenko <sid@itb.spb.ru>
Fri, 21 Nov 2025 11:54:46 +0000 (14:54 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Dec 2025 13:03:27 +0000 (14:03 +0100)
commit03ee076352cf625d7785fc43fce9caf806e7c665
tree569ac8948da242c3f6937362069124c2b1a0bc1c
parent760bc6ceda8e2c273c0e2018ad2595967c3dd308
mtd: lpddr_cmds: fix signed shifts in lpddr_cmds

[ Upstream commit c909fec69f84b39e63876c69b9df2c178c6b76ba ]

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 <sid@itb.spb.ru>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mtd/lpddr/lpddr_cmds.c