Skip to content

Commit c909fec

Browse files
Ivan Stepchenkomiquelraynal
authored andcommitted
mtd: lpddr_cmds: fix signed shifts in lpddr_cmds
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: c682647 ("[MTD] LPDDR Command set driver") Signed-off-by: Ivan Stepchenko <sid@itb.spb.ru> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 1cce5a5 commit c909fec

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/mtd/lpddr/lpddr_cmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct mtd_info *lpddr_cmdset(struct map_info *map)
7979
mutex_init(&shared[i].lock);
8080
for (j = 0; j < lpddr->qinfo->HWPartsNum; j++) {
8181
*chip = lpddr->chips[i];
82-
chip->start += j << lpddr->chipshift;
82+
chip->start += (unsigned long)j << lpddr->chipshift;
8383
chip->oldstate = chip->state = FL_READY;
8484
chip->priv = &shared[i];
8585
/* those should be reset too since
@@ -559,7 +559,7 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
559559
break;
560560

561561
if ((len + ofs - 1) >> lpddr->chipshift)
562-
thislen = (1<<lpddr->chipshift) - ofs;
562+
thislen = (1UL << lpddr->chipshift) - ofs;
563563
else
564564
thislen = len;
565565
/* get the chip */
@@ -575,7 +575,7 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
575575
len -= thislen;
576576

577577
ofs = 0;
578-
last_end += 1 << lpddr->chipshift;
578+
last_end += 1UL << lpddr->chipshift;
579579
chipnum++;
580580
chip = &lpddr->chips[chipnum];
581581
}
@@ -601,7 +601,7 @@ static int lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
601601
break;
602602

603603
if ((len + ofs - 1) >> lpddr->chipshift)
604-
thislen = (1<<lpddr->chipshift) - ofs;
604+
thislen = (1UL << lpddr->chipshift) - ofs;
605605
else
606606
thislen = len;
607607

0 commit comments

Comments
 (0)