Skip to contentSkip to conversation

UBI: check if we are in RO mode in the erase routine

PATCH New Artem Bityutskiy 1 participant 1 message Mar 22, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 UBI: check if we are in RO mode in the erase routine

From: Artem Bityutskiy <[email protected]>

'do_sync_erase()' has to check whether we are in R/O mode before erasing the PEB. This patch adds the check and while on it, adds an assertion which validates the 'pnum' argument, as well as removes a check which is always true because it has already been done few lines before.

---
 drivers/mtd/ubi/io.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/mtd/ubi/io.c +7 -1
index aaa6e1e..9342074 100644
@@ -344,6 +344,12 @@ static int do_sync_erase(struct ubi_device *ubi, int pnum)
 	wait_queue_head_t wq;
 
 	dbg_io("erase PEB %d", pnum);
+	ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
+
+	if (ubi->ro_mode) {
+		ubi_err("read-only mode");
+		return -EROFS;
+	}
 
 retry:
 	init_waitqueue_head(&wq);
@@ -390,7 +396,7 @@ retry:
 	if (err)
 		return err;
 
-	if (ubi_dbg_is_erase_failure() && !err) {
+	if (ubi_dbg_is_erase_failure()) {
 		dbg_err("cannot erase PEB %d (emulated)", pnum);
 		return -EIO;
 	}
Signature · 1 line
1.7.2.3