1 --- a/drivers/mtd/devices/goldfish_nand.c
2 +++ b/drivers/mtd/devices/goldfish_nand.c
3 @@ -65,7 +65,7 @@ static int goldfish_nand_erase(struct mt
6 ofs *= (mtd->writesize + mtd->oobsize);
9 if(len % mtd->writesize)
11 len = len / mtd->writesize * (mtd->writesize + mtd->oobsize);
12 @@ -94,15 +94,12 @@ static int goldfish_nand_read_oob(struct
14 if(ofs + ops->len > mtd->size)
16 - if(ops->datbuf && ops->len && ops->len != mtd->writesize)
18 if(ops->ooblen + ops->ooboffs > mtd->oobsize)
21 rem = do_div(ofs, mtd->writesize);
24 ofs *= (mtd->writesize + mtd->oobsize);
28 ops->retlen = goldfish_nand_cmd(mtd, NAND_CMD_READ, ofs,
29 @@ -131,7 +128,7 @@ static int goldfish_nand_write_oob(struc
31 if(ops->ooblen + ops->ooboffs > mtd->oobsize)
35 rem = do_div(ofs, mtd->writesize);
38 @@ -160,15 +157,24 @@ static int goldfish_nand_read(struct mtd
40 if(from + len > mtd->size)
42 - if(len != mtd->writesize)
47 rem = do_div(from, mtd->writesize);
50 from *= (mtd->writesize + mtd->oobsize);
53 - *retlen = goldfish_nand_cmd(mtd, NAND_CMD_READ, from, len, buf);
55 + *retlen += goldfish_nand_cmd(mtd, NAND_CMD_READ, from, min(len, mtd->writesize - rem), buf);
56 + if (len > mtd->writesize - rem) {
57 + len -= mtd->writesize - rem;
58 + buf += mtd->writesize - rem;
59 + from += mtd->writesize + mtd->oobsize - rem;
68 @@ -184,15 +190,23 @@ static int goldfish_nand_write(struct mt
70 if(to + len > mtd->size)
72 - if(len != mtd->writesize)
75 rem = do_div(to, mtd->writesize);
78 to *= (mtd->writesize + mtd->oobsize);
80 - *retlen = goldfish_nand_cmd(mtd, NAND_CMD_WRITE, to, len, (void *)buf);
83 + *retlen += goldfish_nand_cmd(mtd, NAND_CMD_WRITE, to, min(len, mtd->writesize), (void *)buf);
84 + if (len > mtd->writesize) {
85 + len -= mtd->writesize;
86 + buf += mtd->writesize;
87 + to += mtd->writesize + mtd->oobsize;