Blob Blame History Raw
From 6cab8e0186e73af75f0a15ce87c4db20ef0089df Mon Sep 17 00:00:00 2001
From: Dan Williams <dan.j.williams@intel.com>
Date: Sun, 23 Jan 2022 16:54:01 -0800
Subject: [PATCH 111/217] cxl/memdev: Cleanup memdev filter

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.

Link: https://lore.kernel.org/r/164298564100.3021641.9410483964085163708.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 cxl/memdev.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/cxl/memdev.c b/cxl/memdev.c
index 327c260..4cca8b8 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;
 
-- 
2.27.0