mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-28 20:37:27 +00:00
mtd: Remove duplicate checks on mtd_oob_ops parameter
Some of the check done in custom ->_read/write_oob() implementation are already done by the core (in mtd_check_oob_ops()). Suggested-by: Peter Pan <peterpansjtu@gmail.com> [Remove redundant checks done in mtdpart.c] Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Tested-by: Ladislav Michl <ladis@linux-mips.org>
This commit is contained in:
parent
24ff129222
commit
0aede42e98
@ -904,9 +904,6 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
|
||||
if (ooblen % DOC_LAYOUT_OOB_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
if (from + len > mtd->size)
|
||||
return -EINVAL;
|
||||
|
||||
ops->oobretlen = 0;
|
||||
ops->retlen = 0;
|
||||
ret = 0;
|
||||
@ -1441,8 +1438,6 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
|
||||
if (len && ooblen &&
|
||||
(len / DOC_LAYOUT_PAGE_SIZE) != (ooblen / oobdelta))
|
||||
return -EINVAL;
|
||||
if (ofs + len > mtd->size)
|
||||
return -EINVAL;
|
||||
|
||||
ops->oobretlen = 0;
|
||||
ops->retlen = 0;
|
||||
|
@ -108,25 +108,6 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
|
||||
struct mtd_ecc_stats stats;
|
||||
int res;
|
||||
|
||||
if (from >= mtd->size)
|
||||
return -EINVAL;
|
||||
if (ops->datbuf && from + ops->len > mtd->size)
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* If OOB is also requested, make sure that we do not read past the end
|
||||
* of this partition.
|
||||
*/
|
||||
if (ops->oobbuf) {
|
||||
size_t len, pages;
|
||||
|
||||
len = mtd_oobavail(mtd, ops);
|
||||
pages = mtd_div_by_ws(mtd->size, mtd);
|
||||
pages -= mtd_div_by_ws(from, mtd);
|
||||
if (ops->ooboffs + ops->ooblen > pages * len)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
stats = part->parent->ecc_stats;
|
||||
res = part->parent->_read_oob(part->parent, from + part->offset, ops);
|
||||
if (unlikely(mtd_is_eccerr(res)))
|
||||
@ -191,10 +172,6 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to,
|
||||
{
|
||||
struct mtd_part *part = mtd_to_part(mtd);
|
||||
|
||||
if (to >= mtd->size)
|
||||
return -EINVAL;
|
||||
if (ops->datbuf && to + ops->len > mtd->size)
|
||||
return -EINVAL;
|
||||
return part->parent->_write_oob(part->parent, to + part->offset, ops);
|
||||
}
|
||||
|
||||
|
@ -2187,21 +2187,6 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
|
||||
|
||||
len = mtd_oobavail(mtd, ops);
|
||||
|
||||
if (unlikely(ops->ooboffs >= len)) {
|
||||
pr_debug("%s: attempt to start read outside oob\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Do not allow reads past end of device */
|
||||
if (unlikely(from >= mtd->size ||
|
||||
ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) -
|
||||
(from >> chip->page_shift)) * len)) {
|
||||
pr_debug("%s: attempt to read beyond end of device\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
chipnr = (int)(from >> chip->chip_shift);
|
||||
chip->select_chip(mtd, chipnr);
|
||||
|
||||
@ -2272,13 +2257,6 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
|
||||
|
||||
ops->retlen = 0;
|
||||
|
||||
/* Do not allow reads past end of device */
|
||||
if (ops->datbuf && (from + ops->len) > mtd->size) {
|
||||
pr_debug("%s: attempt to read beyond end of device\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ops->mode != MTD_OPS_PLACE_OOB &&
|
||||
ops->mode != MTD_OPS_AUTO_OOB &&
|
||||
ops->mode != MTD_OPS_RAW)
|
||||
@ -2820,22 +2798,6 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(ops->ooboffs >= len)) {
|
||||
pr_debug("%s: attempt to start write outside oob\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Do not allow write past end of device */
|
||||
if (unlikely(to >= mtd->size ||
|
||||
ops->ooboffs + ops->ooblen >
|
||||
((mtd->size >> chip->page_shift) -
|
||||
(to >> chip->page_shift)) * len)) {
|
||||
pr_debug("%s: attempt to write beyond end of device\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
chipnr = (int)(to >> chip->chip_shift);
|
||||
|
||||
/*
|
||||
@ -2891,13 +2853,6 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
|
||||
|
||||
ops->retlen = 0;
|
||||
|
||||
/* Do not allow writes past end of device */
|
||||
if (ops->datbuf && (to + ops->len) > mtd->size) {
|
||||
pr_debug("%s: attempt to write beyond end of device\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
nand_get_device(mtd, FL_WRITING);
|
||||
|
||||
switch (ops->mode) {
|
||||
|
@ -1383,15 +1383,6 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Do not allow reads past end of device */
|
||||
if (unlikely(from >= mtd->size ||
|
||||
column + len > ((mtd->size >> this->page_shift) -
|
||||
(from >> this->page_shift)) * oobsize)) {
|
||||
printk(KERN_ERR "%s: Attempted to read beyond end of device\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
stats = mtd->ecc_stats;
|
||||
|
||||
readcmd = ONENAND_IS_4KB_PAGE(this) ? ONENAND_CMD_READ : ONENAND_CMD_READOOB;
|
||||
@ -2024,15 +2015,6 @@ static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Do not allow reads past end of device */
|
||||
if (unlikely(to >= mtd->size ||
|
||||
column + len > ((mtd->size >> this->page_shift) -
|
||||
(to >> this->page_shift)) * oobsize)) {
|
||||
printk(KERN_ERR "%s: Attempted to write past end of device\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
oobbuf = this->oob_buf;
|
||||
|
||||
oobcmd = ONENAND_IS_4KB_PAGE(this) ? ONENAND_CMD_PROG : ONENAND_CMD_PROGOOB;
|
||||
|
Loading…
Reference in New Issue
Block a user