summaryrefslogtreecommitdiffstats
path: root/commands/nand.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-02-25 12:54:15 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-03-04 11:00:33 +0100
commit68bd6e930953d2a289adf3b141d3a33b93a1e580 (patch)
tree425236ecd489a5d8d13986c67ddf68ebf644a04a /commands/nand.c
parent938f748103318b937bac50a8b23b150bb947a574 (diff)
downloadbarebox-68bd6e930953d2a289adf3b141d3a33b93a1e580.tar.gz
nand command: check for <dev> directly after option parsing
Allo subcommands need at least one nonopt arg, so check for it right after parsing the options and drop the check in the MARKBAD command. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/nand.c')
-rw-r--r--commands/nand.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/commands/nand.c b/commands/nand.c
index 79f6735..39fb64e 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -58,6 +58,9 @@ static int do_nand(int argc, char *argv[])
}
}
+ if (optind >= argc)
+ return COMMAND_ERROR_USAGE;
+
if (command == NAND_ADD) {
while (optind < argc) {
if (dev_add_bb_dev(basename(argv[optind]), NULL))
@@ -75,25 +78,23 @@ static int do_nand(int argc, char *argv[])
}
if (command == NAND_MARKBAD) {
- if (optind < argc) {
- int ret = 0, fd;
+ int ret = 0, fd;
- printf("marking block at 0x%08llx on %s as bad\n",
- badblock, argv[optind]);
+ printf("marking block at 0x%08llx on %s as bad\n",
+ badblock, argv[optind]);
- fd = open(argv[optind], O_RDWR);
- if (fd < 0) {
- perror("open");
- return 1;
- }
+ fd = open(argv[optind], O_RDWR);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
- ret = ioctl(fd, MEMSETBADBLOCK, &badblock);
- if (ret)
- perror("ioctl");
+ ret = ioctl(fd, MEMSETBADBLOCK, &badblock);
+ if (ret)
+ perror("ioctl");
- close(fd);
- return ret;
- }
+ close(fd);
+ return ret;
}
return 0;