Date:2010-07-16 23:42:05 (13 years 8 months ago)
Author:Lars C.
Commit:f42d987a04d6f9366c47edf794f66796151867b9
Message:MTD: NAND: jz4740: Fix potential that can happen when the hardware is broken

Files: drivers/mtd/nand/jz4740_nand.c (6 diffs)

Change Details

drivers/mtd/nand/jz4740_nand.c
164164    struct jz_nand *nand = mtd_to_jz_nand(mtd);
165165    uint32_t reg, status;
166166    int i;
167    unsigned int timeout = 1000;
167168    static uint8_t empty_block_ecc[] = {0xcd, 0x9d, 0x90, 0x58, 0xf4,
168169                        0x8b, 0xff, 0xb7, 0x6f};
169170
...... 
172173
173174    do {
174175        status = readl(nand->base + JZ_REG_NAND_IRQ_STAT);
175    } while (!(status & JZ_NAND_STATUS_ENC_FINISH));
176    } while (!(status & JZ_NAND_STATUS_ENC_FINISH) && --timeout);
177
178    if (timeout == 0)
179        return -1;
176180
177181    reg = readl(nand->base + JZ_REG_NAND_ECC_CTRL);
178182    reg &= ~JZ_NAND_ECC_CTRL_ENABLE;
...... 
189193    return 0;
190194}
191195
192static void correct_data(uint8_t *dat, int index, int mask)
196static void jz_nand_correct_data(uint8_t *dat, int index, int mask)
193197{
194198    int offset = index & 0x7;
195199    uint16_t data;
...... 
214218    int i, error_count, index;
215219    uint32_t reg, status, error;
216220    uint32_t t;
221    unsigned int timeout = 1000;
217222
218223    t = read_ecc[0];
219224
...... 
242247
243248    do {
244249        status = readl(nand->base + JZ_REG_NAND_IRQ_STAT);
245    } while (!(status & JZ_NAND_STATUS_DEC_FINISH));
250    } while (!(status & JZ_NAND_STATUS_DEC_FINISH) && --timeout);
251
252    if (timeout == 0)
253        return -1;
246254
247255    reg = readl(nand->base + JZ_REG_NAND_ECC_CTRL);
248256    reg &= ~JZ_NAND_ECC_CTRL_ENABLE;
...... 
258266            error = readl(nand->base + JZ_REG_NAND_ERR(i));
259267            index = ((error >> 16) & 0x1ff) - 1;
260268            if (index >= 0 && index < 512)
261                correct_data(dat, index, error & 0x1ff);
269                jz_nand_correct_data(dat, index, error & 0x1ff);
262270        }
263271
264272        return error_count;

Archive Download the corresponding diff file



interactive