mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mtd: core: check offset in mtd_block_markbad
@ 2016-02-15 10:01 Stefan Christ
  2016-02-23  6:56 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Christ @ 2016-02-15 10:01 UTC (permalink / raw)
  To: barebox

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mtd: core: check offset in mtd_block_markbad
  2016-02-15 10:01 [PATCH] mtd: core: check offset in mtd_block_markbad Stefan Christ
@ 2016-02-23  6:56 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2016-02-23  6:56 UTC (permalink / raw)
  To: Stefan Christ; +Cc: barebox

On Mon, Feb 15, 2016 at 11:01:24AM +0100, Stefan Christ wrote:
> 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(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-23  6:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-15 10:01 [PATCH] mtd: core: check offset in mtd_block_markbad Stefan Christ
2016-02-23  6:56 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox