diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-06-06 07:59:14 -0400 |
---|---|---|
committer | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-07-11 02:40:13 -0400 |
commit | 03b1d11a998b70df2ca699a9b9fb8ab5b0746d43 (patch) | |
tree | 7022494a4ad28b70c930eef5fcc254657b00646e /drivers/mtd | |
parent | a92c721dc638b3745266ffe85617fe54dfadff19 (diff) |
mtd: nand: sunxi: fix subpage write
Implement ecc->write_subpage() to prevent core code from assigning this
hook to nand_write_subpage_hwecc(). This default implementation tries
to call ecc->hwctl() which in our case is NULL, thus leading to a NULL
pointer dereference.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/nand/sunxi_nand.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c index 6e319bace724..f582fe41d61d 100644 --- a/drivers/mtd/nand/sunxi_nand.c +++ b/drivers/mtd/nand/sunxi_nand.c | |||
@@ -1352,6 +1352,36 @@ static int sunxi_nfc_hw_ecc_write_page(struct mtd_info *mtd, | |||
1352 | return 0; | 1352 | return 0; |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | static int sunxi_nfc_hw_ecc_write_subpage(struct mtd_info *mtd, | ||
1356 | struct nand_chip *chip, | ||
1357 | u32 data_offs, u32 data_len, | ||
1358 | const u8 *buf, int oob_required, | ||
1359 | int page) | ||
1360 | { | ||
1361 | struct nand_ecc_ctrl *ecc = &chip->ecc; | ||
1362 | int ret, i, cur_off = 0; | ||
1363 | |||
1364 | sunxi_nfc_hw_ecc_enable(mtd); | ||
1365 | |||
1366 | for (i = data_offs / ecc->size; | ||
1367 | i < DIV_ROUND_UP(data_offs + data_len, ecc->size); i++) { | ||
1368 | int data_off = i * ecc->size; | ||
1369 | int oob_off = i * (ecc->bytes + 4); | ||
1370 | const u8 *data = buf + data_off; | ||
1371 | const u8 *oob = chip->oob_poi + oob_off; | ||
1372 | |||
1373 | ret = sunxi_nfc_hw_ecc_write_chunk(mtd, data, data_off, oob, | ||
1374 | oob_off + mtd->writesize, | ||
1375 | &cur_off, !i, page); | ||
1376 | if (ret) | ||
1377 | return ret; | ||
1378 | } | ||
1379 | |||
1380 | sunxi_nfc_hw_ecc_disable(mtd); | ||
1381 | |||
1382 | return 0; | ||
1383 | } | ||
1384 | |||
1355 | static int sunxi_nfc_hw_ecc_write_page_dma(struct mtd_info *mtd, | 1385 | static int sunxi_nfc_hw_ecc_write_page_dma(struct mtd_info *mtd, |
1356 | struct nand_chip *chip, | 1386 | struct nand_chip *chip, |
1357 | const u8 *buf, | 1387 | const u8 *buf, |
@@ -1864,7 +1894,8 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd, | |||
1864 | ecc->write_page = sunxi_nfc_hw_ecc_write_page; | 1894 | ecc->write_page = sunxi_nfc_hw_ecc_write_page; |
1865 | } | 1895 | } |
1866 | 1896 | ||
1867 | /* TODO: support DMA for raw accesses */ | 1897 | /* TODO: support DMA for raw accesses and subpage write */ |
1898 | ecc->write_subpage = sunxi_nfc_hw_ecc_write_subpage; | ||
1868 | ecc->read_oob_raw = nand_read_oob_std; | 1899 | ecc->read_oob_raw = nand_read_oob_std; |
1869 | ecc->write_oob_raw = nand_write_oob_std; | 1900 | ecc->write_oob_raw = nand_write_oob_std; |
1870 | ecc->read_subpage = sunxi_nfc_hw_ecc_read_subpage; | 1901 | ecc->read_subpage = sunxi_nfc_hw_ecc_read_subpage; |