Skip to contentSkip to conversation

dax_io: fix unknown parameter handling

PATCH In review Jeff Moyer 2 participants 2 messages Oct 20, 2017 – Oct 31, 2017 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 dax_io: fix unknown parameter handling

The for loop will not loop more than once due to the return statement. What's more, the following code, which prints out the usage, also won't run. Let's change this to look more like other commands. Print out invalid options and then print out the usage. usage_with_options will exit, so no need for a return there.

daxctl/io.c +2 -6
index 27e7463..2f8cb4a 100644
@@ -526,15 +526,11 @@ int cmd_io(int argc, const char **argv, void *daxctl_ctx)
 	struct ndctl_ctx *ndctl_ctx;
 
 	argc = parse_options(argc, argv, options, u, 0);
-	for (i = 0; i < argc; i++) {
+	for (i = 0; i < argc; i++)
 		fail("Unknown parameter \"%s\"\n", argv[i]);
-		return -EINVAL;
-	}
 
-	if (argc) {
+	if (argc)
 		usage_with_options(u, options);
-		return 0;
-	}
 
 	if (!io.dev[0].parm_path && !io.dev[1].parm_path) {
 		usage_with_options(u, options);

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jeff Moyer

The for loop will not loop more than once due to the return statement. What's more, the following code, which prints out the usage, also won't run. Let's change this to look more like other commands. Print out invalid options and then print out the usage. usage_with_options will exit, so no need for a return there.

Looks good,

Quoted 23 lines
daxctl/io.c +2 -6
index 27e7463..2f8cb4a 100644
@@ -526,15 +526,11 @@ int cmd_io(int argc, const char **argv, void *daxctl_ctx)
 	struct ndctl_ctx *ndctl_ctx;
 
 	argc = parse_options(argc, argv, options, u, 0);
-	for (i = 0; i < argc; i++) {
+	for (i = 0; i < argc; i++)
 		fail("Unknown parameter \"%s\"\n", argv[i]);
-		return -EINVAL;
-	}
 
-	if (argc) {
+	if (argc)
 		usage_with_options(u, options);
-		return 0;
-	}
 
 	if (!io.dev[0].parm_path && !io.dev[1].parm_path) {
 		usage_with_options(u, options);
Quoted 4 lines

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm