mtd: create an mtd_oobavail() helper and make use of it
Currently, all MTD drivers/sublayers exposing an OOB area are doing the same kind of test to extract the available OOB size based on the mtd_info and mtd_oob_ops structures. Move this common logic into an inline function and make use of it. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Suggested-by: Priit Laes <plaes@plaes.org> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
This commit is contained in:
parent
f5b8aa78ef
commit
29f1058a90
|
@ -126,10 +126,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
|
||||||
if (ops->oobbuf) {
|
if (ops->oobbuf) {
|
||||||
size_t len, pages;
|
size_t len, pages;
|
||||||
|
|
||||||
if (ops->mode == MTD_OPS_AUTO_OOB)
|
len = mtd_oobavail(mtd, ops);
|
||||||
len = mtd->oobavail;
|
|
||||||
else
|
|
||||||
len = mtd->oobsize;
|
|
||||||
pages = mtd_div_by_ws(mtd->size, mtd);
|
pages = mtd_div_by_ws(mtd->size, mtd);
|
||||||
pages -= mtd_div_by_ws(from, mtd);
|
pages -= mtd_div_by_ws(from, mtd);
|
||||||
if (ops->ooboffs + ops->ooblen > pages * len)
|
if (ops->ooboffs + ops->ooblen > pages * len)
|
||||||
|
|
|
@ -1723,8 +1723,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
uint32_t readlen = ops->len;
|
uint32_t readlen = ops->len;
|
||||||
uint32_t oobreadlen = ops->ooblen;
|
uint32_t oobreadlen = ops->ooblen;
|
||||||
uint32_t max_oobsize = ops->mode == MTD_OPS_AUTO_OOB ?
|
uint32_t max_oobsize = mtd_oobavail(mtd, ops);
|
||||||
mtd->oobavail : mtd->oobsize;
|
|
||||||
|
|
||||||
uint8_t *bufpoi, *oob, *buf;
|
uint8_t *bufpoi, *oob, *buf;
|
||||||
int use_bufpoi;
|
int use_bufpoi;
|
||||||
|
@ -2075,10 +2074,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
|
||||||
|
|
||||||
stats = mtd->ecc_stats;
|
stats = mtd->ecc_stats;
|
||||||
|
|
||||||
if (ops->mode == MTD_OPS_AUTO_OOB)
|
len = mtd_oobavail(mtd, ops);
|
||||||
len = mtd->oobavail;
|
|
||||||
else
|
|
||||||
len = mtd->oobsize;
|
|
||||||
|
|
||||||
if (unlikely(ops->ooboffs >= len)) {
|
if (unlikely(ops->ooboffs >= len)) {
|
||||||
pr_debug("%s: attempt to start read outside oob\n",
|
pr_debug("%s: attempt to start read outside oob\n",
|
||||||
|
@ -2575,8 +2571,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
|
||||||
uint32_t writelen = ops->len;
|
uint32_t writelen = ops->len;
|
||||||
|
|
||||||
uint32_t oobwritelen = ops->ooblen;
|
uint32_t oobwritelen = ops->ooblen;
|
||||||
uint32_t oobmaxlen = ops->mode == MTD_OPS_AUTO_OOB ?
|
uint32_t oobmaxlen = mtd_oobavail(mtd, ops);
|
||||||
mtd->oobavail : mtd->oobsize;
|
|
||||||
|
|
||||||
uint8_t *oob = ops->oobbuf;
|
uint8_t *oob = ops->oobbuf;
|
||||||
uint8_t *buf = ops->datbuf;
|
uint8_t *buf = ops->datbuf;
|
||||||
|
@ -2766,10 +2761,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
|
||||||
pr_debug("%s: to = 0x%08x, len = %i\n",
|
pr_debug("%s: to = 0x%08x, len = %i\n",
|
||||||
__func__, (unsigned int)to, (int)ops->ooblen);
|
__func__, (unsigned int)to, (int)ops->ooblen);
|
||||||
|
|
||||||
if (ops->mode == MTD_OPS_AUTO_OOB)
|
len = mtd_oobavail(mtd, ops);
|
||||||
len = mtd->oobavail;
|
|
||||||
else
|
|
||||||
len = mtd->oobsize;
|
|
||||||
|
|
||||||
/* Do not allow write past end of page */
|
/* Do not allow write past end of page */
|
||||||
if ((ops->ooboffs + ops->ooblen) > len) {
|
if ((ops->ooboffs + ops->ooblen) > len) {
|
||||||
|
|
|
@ -1124,11 +1124,7 @@ static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from,
|
||||||
pr_debug("%s: from = 0x%08x, len = %i\n", __func__, (unsigned int)from,
|
pr_debug("%s: from = 0x%08x, len = %i\n", __func__, (unsigned int)from,
|
||||||
(int)len);
|
(int)len);
|
||||||
|
|
||||||
if (ops->mode == MTD_OPS_AUTO_OOB)
|
oobsize = mtd_oobavail(mtd, ops);
|
||||||
oobsize = mtd->oobavail;
|
|
||||||
else
|
|
||||||
oobsize = mtd->oobsize;
|
|
||||||
|
|
||||||
oobcolumn = from & (mtd->oobsize - 1);
|
oobcolumn = from & (mtd->oobsize - 1);
|
||||||
|
|
||||||
/* Do not allow reads past end of device */
|
/* Do not allow reads past end of device */
|
||||||
|
@ -1229,11 +1225,7 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
|
||||||
pr_debug("%s: from = 0x%08x, len = %i\n", __func__, (unsigned int)from,
|
pr_debug("%s: from = 0x%08x, len = %i\n", __func__, (unsigned int)from,
|
||||||
(int)len);
|
(int)len);
|
||||||
|
|
||||||
if (ops->mode == MTD_OPS_AUTO_OOB)
|
oobsize = mtd_oobavail(mtd, ops);
|
||||||
oobsize = mtd->oobavail;
|
|
||||||
else
|
|
||||||
oobsize = mtd->oobsize;
|
|
||||||
|
|
||||||
oobcolumn = from & (mtd->oobsize - 1);
|
oobcolumn = from & (mtd->oobsize - 1);
|
||||||
|
|
||||||
/* Do not allow reads past end of device */
|
/* Do not allow reads past end of device */
|
||||||
|
@ -1885,12 +1877,7 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
|
||||||
/* Check zero length */
|
/* Check zero length */
|
||||||
if (!len)
|
if (!len)
|
||||||
return 0;
|
return 0;
|
||||||
|
oobsize = mtd_oobavail(mtd, ops);
|
||||||
if (ops->mode == MTD_OPS_AUTO_OOB)
|
|
||||||
oobsize = mtd->oobavail;
|
|
||||||
else
|
|
||||||
oobsize = mtd->oobsize;
|
|
||||||
|
|
||||||
oobcolumn = to & (mtd->oobsize - 1);
|
oobcolumn = to & (mtd->oobsize - 1);
|
||||||
|
|
||||||
column = to & (mtd->writesize - 1);
|
column = to & (mtd->writesize - 1);
|
||||||
|
|
|
@ -264,6 +264,11 @@ static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd)
|
||||||
return mtd->dev.of_node;
|
return mtd->dev.of_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops)
|
||||||
|
{
|
||||||
|
return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;
|
||||||
|
}
|
||||||
|
|
||||||
int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
|
int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
|
||||||
int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
|
int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
|
||||||
void **virt, resource_size_t *phys);
|
void **virt, resource_size_t *phys);
|
||||||
|
|
Loading…
Reference in New Issue