diff mbox series

mtd: rawnand: gpmi: check nand_read_page_op() return value

Message ID 20190528104054.21018-1-s.hauer@pengutronix.de
State Superseded
Delegated to: Miquel Raynal
Headers show
Series mtd: rawnand: gpmi: check nand_read_page_op() return value | expand

Commit Message

Sascha Hauer May 28, 2019, 10:40 a.m. UTC
nand_read_page_op() can fail, so check its return value and bail out
with an error when necessary.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 38 ++++++++++++++++++----
 1 file changed, 31 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
index e0080dcd4fc0..5db84178edff 100644
--- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
@@ -1451,11 +1451,14 @@  static int gpmi_ecc_read_page(struct nand_chip *chip, uint8_t *buf,
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	struct bch_geometry *geo = &this->bch_geometry;
 	unsigned int max_bitflips;
+	int ret;
 
 	gpmi_bch_layout_std(this);
 	this->bch = true;
 
-	nand_read_page_op(chip, page, 0, buf, geo->page_size);
+	ret = nand_read_page_op(chip, page, 0, buf, geo->page_size);
+	if (ret)
+		return ret;
 
 	max_bitflips = gpmi_count_bitflips(chip, buf, 0,
 					   geo->ecc_chunk_count,
@@ -1495,6 +1498,7 @@  static int gpmi_ecc_read_subpage(struct nand_chip *chip, uint32_t offs,
 	int first, last, marker_pos;
 	int ecc_parity_size;
 	int col = 0;
+	int ret;
 
 	/* The size of ECC parity */
 	ecc_parity_size = geo->gf_len * geo->ecc_strength / 8;
@@ -1546,7 +1550,9 @@  static int gpmi_ecc_read_subpage(struct nand_chip *chip, uint32_t offs,
 
 	this->bch = true;
 
-	nand_read_page_op(chip, page, col, buf, page_size);
+	ret = nand_read_page_op(chip, page, col, buf, page_size);
+	if (ret)
+		return ret;
 
 	dev_dbg(this->dev, "page:%d(%d:%d)%d, chunk:(%d:%d), BCH PG size:%d\n",
 		page, offs, len, col, first, n, page_size);
@@ -1651,12 +1657,16 @@  static int gpmi_ecc_read_oob(struct nand_chip *chip, int page)
 {
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	struct gpmi_nand_data *this = nand_get_controller_data(chip);
+	int ret;
 
 	/* clear the OOB buffer */
 	memset(chip->oob_poi, ~0, mtd->oobsize);
 
 	/* Read out the conventional OOB. */
-	nand_read_page_op(chip, page, mtd->writesize, chip->oob_poi, mtd->oobsize);
+	ret = nand_read_page_op(chip, page, mtd->writesize, chip->oob_poi,
+				mtd->oobsize);
+	if (ret)
+		return ret;
 
 	/*
 	 * Now, we want to make sure the block mark is correct. In the
@@ -1665,7 +1675,9 @@  static int gpmi_ecc_read_oob(struct nand_chip *chip, int page)
 	 */
 	if (GPMI_IS_MX23(this)) {
 		/* Read the block mark into the first byte of the OOB buffer. */
-		nand_read_page_op(chip, page, 0, chip->oob_poi, 1);
+		ret = nand_read_page_op(chip, page, 0, chip->oob_poi, 1);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
@@ -1714,8 +1726,12 @@  static int gpmi_ecc_read_page_raw(struct nand_chip *chip, uint8_t *buf,
 	size_t oob_byte_off;
 	uint8_t *oob = chip->oob_poi;
 	int step;
+	int ret;
 
-	nand_read_page_op(chip, page, 0, tmp_buf, mtd->writesize + mtd->oobsize);
+	ret = nand_read_page_op(chip, page, 0, tmp_buf,
+				mtd->writesize + mtd->oobsize);
+	if (ret)
+		return ret;
 
 	/*
 	 * If required, swap the bad block marker and the data stored in the
@@ -1928,6 +1944,7 @@  static int mx23_check_transcription_stamp(struct gpmi_nand_data *this)
 	unsigned int page;
 	u8 *buffer = nand_get_data_buf(chip);
 	int found_an_ncb_fingerprint = false;
+	int ret;
 
 	/* Compute the number of strides in a search area. */
 	search_area_size_in_strides = 1 << rom_geo->search_area_stride_exponent;
@@ -1949,7 +1966,10 @@  static int mx23_check_transcription_stamp(struct gpmi_nand_data *this)
 		 * Read the NCB fingerprint. The fingerprint is four bytes long
 		 * and starts in the 12th byte of the page.
 		 */
-		nand_read_page_op(chip, page, 12, buffer, strlen(fingerprint));
+		ret = nand_read_page_op(chip, page, 12, buffer,
+					strlen(fingerprint));
+		if (ret)
+			continue;
 
 		/* Look for the fingerprint. */
 		if (!memcmp(buffer, fingerprint, strlen(fingerprint))) {
@@ -2081,9 +2101,13 @@  static int mx23_boot_init(struct gpmi_nand_data  *this)
 
 		/* Send the command to read the conventional block mark. */
 		nand_select_target(chip, chipnr);
-		nand_read_page_op(chip, page, mtd->writesize, &block_mark, 1);
+		ret = nand_read_page_op(chip, page, mtd->writesize, &block_mark,
+					1);
 		nand_deselect_target(chip);
 
+		if (ret)
+			continue;
+
 		/*
 		 * Check if the block is marked bad. If so, we need to mark it
 		 * again, but this time the result will be a mark in the