mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Stefan Christ <s.christ@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCH] mtd: core: check offset in mtd_block_markbad
Date: Mon, 15 Feb 2016 11:01:24 +0100	[thread overview]
Message-ID: <1455530484-17750-1-git-send-email-s.christ@phytec.de> (raw)

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@phytec.de>
---
 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2016-02-15 10:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-15 10:01 Stefan Christ [this message]
2016-02-23  6:56 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455530484-17750-1-git-send-email-s.christ@phytec.de \
    --to=s.christ@phytec.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox