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

Commit 4ac704d3 authored by Tatyana Brokhman's avatar Tatyana Brokhman
Browse files

mtd: msm_qpic_nand: Support for partial page read - fix



In case the required read length is smaller the mtd->writesize, the whole
erase block is still read but only part of it (the required length) is
returned to the user.
This patch updated the calculation of retlen (number of bytes read).

Change-Id: I377ea88f1c3fa4fc136f09f2e43db4d7ebcd4a1b
Signed-off-by: default avatarTatyana Brokhman <tlinder@codeaurora.org>
parent 555a56b8
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -1767,9 +1767,10 @@ static int msm_nand_read_partial_page(struct mtd_info *mtd,
	loff_t aligned_from;
	loff_t offset;
	size_t len;
	size_t actual_len;
	size_t actual_len, ret_len;

	actual_len = ops->len;
	ret_len = 0;
	actual_buf = ops->datbuf;

	bounce_buf = kmalloc(mtd->writesize, GFP_KERNEL);
@@ -1796,14 +1797,17 @@ static int msm_nand_read_partial_page(struct mtd_info *mtd,

		ops->datbuf = no_copy ? actual_buf : bounce_buf;
		err = msm_nand_read_oob(mtd, aligned_from, ops);
		if (err < 0)
		if (err < 0) {
			ret_len = ops->retlen;
			break;
		}

		if (!no_copy)
			memcpy(actual_buf, bounce_buf + offset, len);

		actual_len -= len;
		ops->retlen += len;
		ret_len += len;

		if (actual_len == 0)
			break;

@@ -1812,6 +1816,7 @@ static int msm_nand_read_partial_page(struct mtd_info *mtd,
		aligned_from += mtd->writesize;
	}

	ops->retlen = ret_len;
	kfree(bounce_buf);
out:
	return err;
@@ -1847,13 +1852,21 @@ static int msm_nand_read(struct mtd_info *mtd, loff_t from, size_t len,
				if (ret < 0)
					break;

				len -= mtd->writesize;
				*retlen += mtd->writesize;
				len -= ops.retlen;
				*retlen += ops.retlen;
				if (len == 0)
					break;
				buf += ops.retlen;
				from += ops.retlen;

				buf += mtd->writesize;
				from += mtd->writesize;
				if (len < mtd->writesize) {
					ops.len = len;
					ops.datbuf = buf;
					ret = msm_nand_read_partial_page(
						mtd, from, &ops);
					*retlen += ops.retlen;
					break;
				}
			}
		} else {
			ops.len = len;