Skip to contentSkip to conversation

mtd: nand: fix integer widening problems

PATCH New Brian Norris 1 participant 1 message Jul 22, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: nand: fix integer widening problems

chip->pagebuf is a 32-bit type (int), so the shift will only be applied as 32-bit. Fix this for 64-bit safety.

Caught by Coverity.

---
I haven't confirmed through tests, but this likely could be pretty dangerous. Perhaps it should be marked for -stable? (In the meantime, maybe I'll see if I can rig up a test case that fails.)

 drivers/mtd/nand/nand_base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/nand_base.c +2 -2
index d8cdf06343fb..4ffb06b8138d 100644
@@ -2391,8 +2391,8 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
 	blockmask = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
 
 	/* Invalidate the page cache, when we write to the cached page */
-	if (to <= (chip->pagebuf << chip->page_shift) &&
-	    (chip->pagebuf << chip->page_shift) < (to + ops->len))
+	if (to <= ((loff_t)chip->pagebuf << chip->page_shift) &&
+	    ((loff_t)chip->pagebuf << chip->page_shift) < (to + ops->len))
 		chip->pagebuf = -1;
 
 	/* Don't allow multipage oob writes with offset */
Signature · 1 line
1.9.1