Commit aeb93af9 authored by Boris Brezillon's avatar Boris Brezillon

mtd: nand: Only allocate ecc->{calc, code}_buf when actually needed

The only users of the ecc->{calc,code}_buf buffers are NAND controller
drivers implementing ecc->calculate() and/or ecc->correct(). Since the
->oobsize can be non-negligle, especially on modern NAND devices, we'd
better allocate it only when it is actually required.

Make ecc->{calc,code}_buf allocation dependent on the presence of
ecc->calculate() or ecc->correct().
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Reviewed-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
parent 8c677541
...@@ -5318,21 +5318,9 @@ int nand_scan_tail(struct mtd_info *mtd) ...@@ -5318,21 +5318,9 @@ int nand_scan_tail(struct mtd_info *mtd)
return -EINVAL; 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); chip->data_buf = kmalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL);
if (!chip->data_buf) { if (!chip->data_buf)
ret = -ENOMEM; return -ENOMEM;
goto err_free_buf;
}
/* /*
* FIXME: some NAND manufacturer drivers expect the first die to be * FIXME: some NAND manufacturer drivers expect the first die to be
...@@ -5495,6 +5483,15 @@ int nand_scan_tail(struct mtd_info *mtd) ...@@ -5495,6 +5483,15 @@ int nand_scan_tail(struct mtd_info *mtd)
goto err_nand_manuf_cleanup; 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 */ /* For many systems, the standard OOB write also works for raw */
if (!ecc->read_oob_raw) if (!ecc->read_oob_raw)
ecc->read_oob_raw = ecc->read_oob; ecc->read_oob_raw = ecc->read_oob;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment