diff mbox series

[ndctl,25/37] cxl/memdev: Cleanup memdev filter

Message ID 164298564100.3021641.9410483964085163708.stgit@dwillia2-desk3.amr.corp.intel.com
State New, archived
Headers show
Series cxl: Full topology enumeration | expand

Commit Message

Dan Williams Jan. 24, 2022, 12:54 a.m. UTC
util_cxl_memdev_filter() already handles the difference between 'mem%d',
'%d', and 'all' for the identifier format. Drop the duplicate / incomplete
format checking.

If the checking for bad formats was dropped too then this command could
support "0,1,2" syntax in addition to "0 1 2" like 'cxl list'. However, it is
not clear that's worthwhile since 'list' is ok to be imprecise, but memdev
commands need to be stricter.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 cxl/memdev.c |   18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/cxl/memdev.c b/cxl/memdev.c
index 327c2608f179..4cca8b8c10be 100644
--- a/cxl/memdev.c
+++ b/cxl/memdev.c
@@ -191,16 +191,16 @@  static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
 		usage_with_options(u, options);
 	for (i = 0; i < argc; i++) {
 		if (strcmp(argv[i], "all") == 0) {
-			argv[0] = "all";
 			argc = 1;
 			break;
 		}
+		if (sscanf(argv[i], "mem%lu", &id) == 1)
+			continue;
+		if (sscanf(argv[i], "%lu", &id) == 1)
+			continue;
 
-		if (sscanf(argv[i], "mem%lu", &id) != 1) {
-			log_err(&ml, "'%s' is not a valid memdev name\n",
-				argv[i]);
-			err++;
-		}
+		log_err(&ml, "'%s' is not a valid memdev name\n", argv[i]);
+		err++;
 	}
 
 	if (err == argc) {
@@ -243,11 +243,7 @@  static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
 	count = 0;
 
 	for (i = 0; i < argc; i++) {
-		if (sscanf(argv[i], "mem%lu", &id) != 1
-				&& strcmp(argv[i], "all") != 0)
-			continue;
-
-		cxl_memdev_foreach (ctx, memdev) {
+		cxl_memdev_foreach(ctx, memdev) {
 			if (!util_cxl_memdev_filter(memdev, argv[i], NULL))
 				continue;