1 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
2 +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
3 @@ -1003,33 +1003,30 @@ static int brcmnand_hamming_ooblayout_fr
4 struct brcmnand_cfg *cfg = &host->hwcfg;
5 int sas = cfg->spare_area_size << cfg->sector_size_1k;
6 int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
9 - if (section >= sectors * 2)
10 + if (section > sectors)
13 - oobregion->offset = (section / 2) * sas;
14 + next = (section * sas);
15 + if (section < sectors)
19 - oobregion->offset += 9;
20 - oobregion->length = 7;
22 + oobregion->offset = ((section - 1) * sas) + 9;
24 - oobregion->length = 6;
26 - /* First sector of each page may have BBI */
29 - * Small-page NAND use byte 6 for BBI while large-page
30 - * NAND use bytes 0 and 1.
32 - if (cfg->page_size > 512) {
33 - oobregion->offset += 2;
34 - oobregion->length -= 2;
36 - oobregion->length--;
38 + if (cfg->page_size > 512) {
39 + /* Large page NAND uses first 2 bytes for BBI */
40 + oobregion->offset = 2;
42 + /* Small page NAND uses last byte before ECC for BBI */
43 + oobregion->offset = 0;
48 + oobregion->length = next - oobregion->offset;