return -EINVAL;
}
- ecc->calc_buf = kmalloc(mtd->oobsize, GFP_KERNEL);
- if (!ecc->calc_buf)
- return -ENOMEM;
-
- ecc->code_buf = kmalloc(mtd->oobsize, GFP_KERNEL);
- if (!ecc->code_buf) {
- ret = -ENOMEM;
- goto err_free_buf;
- }
-
chip->data_buf = kmalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL);
- if (!chip->data_buf) {
- ret = -ENOMEM;
- goto err_free_buf;
- }
+ if (!chip->data_buf)
+ return -ENOMEM;
/*
* FIXME: some NAND manufacturer drivers expect the first die to be
goto err_nand_manuf_cleanup;
}
+ if (ecc->correct || ecc->calculate) {
+ ecc->calc_buf = kmalloc(mtd->oobsize, GFP_KERNEL);
+ ecc->code_buf = kmalloc(mtd->oobsize, GFP_KERNEL);
+ if (!ecc->calc_buf || !ecc->code_buf) {
+ ret = -ENOMEM;
+ goto err_nand_manuf_cleanup;
+ }
+ }
+
/* For many systems, the standard OOB write also works for raw */
if (!ecc->read_oob_raw)
ecc->read_oob_raw = ecc->read_oob;