mtd: nand: Fix bad block marking for blocks with specific offsets in BBT
Subsystems (2)
PATCH 1/1 mtd: nand: Fix bad block marking for blocks with specific offsets in BBT
When BITS_PER_LONG is 32 and offs is in the range [29, 31], the GENMASK macro produces a negative shift count. This undefined behavior causes the bad block marking process to fail.
Signed-off-by Echo Hou <[email protected]>
--- drivers/mtd/nand/bbt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/nand/bbt.c +5 -1
@@ -115,12 +115,16 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,unsigned long *pos = nand->bbt.cache + ((entry * bits_per_block) /BITS_PER_LONG );unsigned int offs = (entry * bits_per_block) %BITS_PER_LONG ; +unsigned int offs_h = offs + bits_per_block -1 ;unsigned long val = status &GENMASK (bits_per_block -1 ,0 );if (entry >=nanddev_neraseblocks (nand))return -ERANGE ; - pos[0 ] &= ~GENMASK (offs + bits_per_block -1 , offs); +if (offs_h >BITS_PER_LONG -1 ) + offs_h =BITS_PER_LONG -1 ; + + pos[0 ] &= ~GENMASK (offs_h, offs); pos[0 ] |= val << offs;if (bits_per_block + offs >BITS_PER_LONG ) {
Signature · 1 line
2.43.0