Skip to contentSkip to conversation

Casting bug in nand_default_block_markbad

PATCH In review Andre Renaud 2 participants 2 messages Apr 11, 2007 – Apr 14, 2007 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Casting bug in nand_default_block_markbad

There is a slight bug in nand_default_block_markbad, where the offset is cast to an integer, prior to being shifted. This means that on large offsets, it is incorrectly doing a signed shift & losing bits. Fixed this by doing the cast after the shift (as is done elsewhere in the code).

mtd/nand/nand_base.c (working copy) renamed from mtd/nand/nand_base.c (revision 957) +1 -1
Index: drivers/mtd/nand/nand_base.c
===================================================================
@@ -355,7 +355,7 @@
        int block, ret;
 
        /* Get block number */
-       block = ((int)ofs) >> chip->bbt_erase_shift;
+       block = (int)(ofs >> chip->bbt_erase_shift);
        if (chip->bbt)
                chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
 
Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solutions Centre

       Andre Renaud                             Bluewater Systems Ltd
Phone: +64 3 3779127 (Aus 1 800 148 751)        Level 17, 119 Armagh St
Fax:   +64 3 3779135                            PO Box 13889
Email: [email protected]                 Christchurch
Web:   http://www.bluewatersys.com              New Zealand
#1 lore raw

mtd/nand/nand_base.c (working copy)

Quoted 11 lines · Andre Renaud

There is a slight bug in nand_default_block_markbad, where the offset is cast to an integer, prior to being shifted. This means that on large offsets, it is incorrectly doing a signed shift & losing bits. Fixed this by doing the cast after the shift (as is done elsewhere in the code).

Index: drivers/mtd/nand/nand_base.c
===================================================================

mtd/nand/nand_base.c (working copy) renamed from mtd/nand/nand_base.c (revision 957) +0 -0

Please provide patches which can be applied with -p1, i.e. do the diff one directory level up

mtd/nand/nand_base.c (working copy) line 360

Quoted 8 lines
mtd/nand/nand_base.c (working copy) renamed from mtd/nand/nand_base.c (revision 957) +1 -1
@@ -355,7 +355,7 @@
        int block, ret;
 
        /* Get block number */
-       block = ((int)ofs) >> chip->bbt_erase_shift;
+       block = (int)(ofs >> chip->bbt_erase_shift);
        if (chip->bbt)
                chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);

Also your patch is whitespace damaged and does not apply. There is some HOWTO submit patches with Thunderbird somewhere in the net.

I fix that up manually.

Thanks,

tglx