[Skiboot] [PATCH 4/4] external/pflash: Fix not checking return values in set_ecc().

Cyril Bur cyril.bur at au1.ibm.com
Wed Aug 16 19:35:40 AEST 2017


When writing ECC bytes to ECC regions we don't check that
blocklevel_write() succeeds nor we check that the region was correctly
erased prior to setting the ECC bytes.

Fixes: CID 163737
Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
 external/pflash/pflash.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index ceab3f44..bfc975fe 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -372,18 +372,27 @@ static int set_ecc(struct flash_details *flash, uint32_t start, uint32_t size)
 	uint32_t i = start + 8;
 	uint8_t ecc = 0;
 	bool confirm;
+	int rc;
 
 	printf("About to erase and set ECC bits in region 0x%08x to 0x%08x\n", start, start + size);
 	confirm = check_confirm();
 	if (!confirm)
 		return 1;
 
-	erase_range(flash, start, size, true, NULL, 0);
+	rc = erase_range(flash, start, size, true, NULL, 0);
+	if (rc) {
+		fprintf(stderr, "Couldn't erase region to mark with ECC\n");
+		return rc;
+	}
 
 	printf("Programming ECC bits...\n");
 	progress_init(size);
 	while (i < start + size) {
-		blocklevel_write(flash->bl, i, &ecc, sizeof(ecc));
+		rc = blocklevel_write(flash->bl, i, &ecc, sizeof(ecc));
+		if (rc) {
+			fprintf(stderr, "\nError setting ECC byte at 0x%08x\n", i);
+			return rc;
+		}
 		i += 9;
 		progress_tick(i - start);
 	}
-- 
2.14.1



More information about the Skiboot mailing list