Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7baef12 authored by Robert Jarzmik's avatar Robert Jarzmik Committed by David Woodhouse
Browse files

mtd: docg3 fix inbound calculations



The last erase block was not accessible, as the out of bound
check was incorrectly rejecting the last block.
The read/write/erase offset checks were forbidding the usage of the
last block, because of the calculation which was considering the
byte after the last instead of the last byte.

Signed-off-by: default avatarRobert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent a78da287
Loading
Loading
Loading
Loading
+5 −12
Original line number Original line Diff line number Diff line
@@ -872,11 +872,8 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
	if (ooblen % DOC_LAYOUT_OOB_SIZE)
	if (ooblen % DOC_LAYOUT_OOB_SIZE)
		return -EINVAL;
		return -EINVAL;


	ret = -EINVAL;
	if (from + len > mtd->size)
	calc_block_sector(from + len, &block0, &block1, &page, &ofs,
		return -EINVAL;
			  docg3->reliable);
	if (block1 > docg3->max_block)
		goto err;


	ops->oobretlen = 0;
	ops->oobretlen = 0;
	ops->retlen = 0;
	ops->retlen = 0;
@@ -1207,7 +1204,7 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *info)
	calc_block_sector(info->addr + info->len, &block0, &block1, &page,
	calc_block_sector(info->addr + info->len, &block0, &block1, &page,
			  &ofs, docg3->reliable);
			  &ofs, docg3->reliable);
	ret = -EINVAL;
	ret = -EINVAL;
	if (block1 > docg3->max_block || page || ofs)
	if (info->addr + info->len > mtd->size || page || ofs)
		goto reset_err;
		goto reset_err;


	ret = 0;
	ret = 0;
@@ -1443,12 +1440,8 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
	if (len && ooblen &&
	if (len && ooblen &&
	    (len / DOC_LAYOUT_PAGE_SIZE) != (ooblen / oobdelta))
	    (len / DOC_LAYOUT_PAGE_SIZE) != (ooblen / oobdelta))
		return -EINVAL;
		return -EINVAL;

	if (ofs + len > mtd->size)
	ret = -EINVAL;
		return -EINVAL;
	calc_block_sector(ofs + len, &block0, &block1, &page, &pofs,
			  docg3->reliable);
	if (block1 > docg3->max_block)
		goto err;


	ops->oobretlen = 0;
	ops->oobretlen = 0;
	ops->retlen = 0;
	ops->retlen = 0;