summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorOleg.Karfich@wago.com <Oleg.Karfich@wago.com>2018-08-15 07:07:40 +0000
committerSascha Hauer <s.hauer@pengutronix.de>2018-08-17 08:18:18 +0200
commita55c7090e783ad6cba78722bf34cb36b3ccff3eb (patch)
tree15f21cd8bf799221972749807e2431f2eac2fb02 /commands
parent0f3782db8adce2cc17849493d4bc8d1f2babd394 (diff)
downloadbarebox-a55c7090e783ad6cba78722bf34cb36b3ccff3eb.tar.gz
nand command: fix null pointer when adding/deleting a bb device
Commit 40ee300 introduces info option about bad blocks. The open() function call is therefore moved out from mark good/bad block to use the filedescriptor in info option too. If someone tries to add/delete a bb device the optind variable is incremented and the open() call gets a null pointer. Fix this issue by returning when the bb device is added/deleted. Signed-off-by: Oleg Karfich <oleg.karfich@wago.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/nand.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/commands/nand.c b/commands/nand.c
index b065a66..c57b394 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -41,7 +41,7 @@ static int do_nand(int argc, char *argv[])
int command = 0;
loff_t badblock = 0;
int fd;
- int ret;
+ int ret = 0;
struct mtd_info_user mtdinfo;
while((opt = getopt(argc, argv, "adb:g:i")) > 0) {
@@ -88,13 +88,18 @@ static int do_nand(int argc, char *argv[])
optind++;
}
+
+ goto out_ret;
}
if (command == NAND_DEL) {
while (optind < argc) {
- dev_remove_bb_dev(basename(argv[optind]));
+ if (dev_remove_bb_dev(basename(argv[optind])))
+ return 1;
optind++;
}
+
+ goto out_ret;
}
fd = open(argv[optind], O_RDWR);
@@ -149,10 +154,10 @@ static int do_nand(int argc, char *argv[])
printf("No bad blocks\n");
}
- ret = 0;
out:
close(fd);
+out_ret:
return ret;
}