[PATCH] mtd: core: check offset in mtd_block_markbad

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Check if the given offset is valid for the mtd device. Print an error
message if not to inform the user in the command 'nand'.

Signed-off-by: Stefan Christ <s.christ@xxxxxxxxx>
---
 commands/nand.c    | 9 +++++++--
 drivers/mtd/core.c | 3 +++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/commands/nand.c b/commands/nand.c
index ad1c8c9..c330ad1 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -90,8 +90,13 @@ static int do_nand(int argc, char *argv[])
 		}
 
 		ret = ioctl(fd, MEMSETBADBLOCK, &badblock);
-		if (ret)
-			perror("ioctl");
+		if (ret) {
+			if (ret == -EINVAL)
+				printf("Maybe offset %lld is out of range.\n",
+					badblock);
+			else
+				perror("ioctl");
+		}
 
 		close(fd);
 		return ret;
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 62307db..d609688 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -310,6 +310,9 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
 {
 	int ret;
 
+	if (ofs < 0 || ofs >= mtd->size)
+		return -EINVAL;
+
 	if (mtd->block_markbad)
 		ret = mtd->block_markbad(mtd, ofs);
 	else
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux