anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone
e0018b
From 6cab8e0186e73af75f0a15ce87c4db20ef0089df Mon Sep 17 00:00:00 2001
e0018b
From: Dan Williams <dan.j.williams@intel.com>
e0018b
Date: Sun, 23 Jan 2022 16:54:01 -0800
e0018b
Subject: [PATCH 111/217] cxl/memdev: Cleanup memdev filter
e0018b
e0018b
util_cxl_memdev_filter() already handles the difference between 'mem%d',
e0018b
'%d', and 'all' for the identifier format. Drop the duplicate / incomplete
e0018b
format checking.
e0018b
e0018b
If the checking for bad formats was dropped too then this command could
e0018b
support "0,1,2" syntax in addition to "0 1 2" like 'cxl list'. However, it is
e0018b
not clear that's worthwhile since 'list' is ok to be imprecise, but memdev
e0018b
commands need to be stricter.
e0018b
e0018b
Link: https://lore.kernel.org/r/164298564100.3021641.9410483964085163708.stgit@dwillia2-desk3.amr.corp.intel.com
e0018b
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 cxl/memdev.c | 18 +++++++-----------
e0018b
 1 file changed, 7 insertions(+), 11 deletions(-)
e0018b
e0018b
diff --git a/cxl/memdev.c b/cxl/memdev.c
e0018b
index 327c260..4cca8b8 100644
e0018b
--- a/cxl/memdev.c
e0018b
+++ b/cxl/memdev.c
e0018b
@@ -191,16 +191,16 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
e0018b
 		usage_with_options(u, options);
e0018b
 	for (i = 0; i < argc; i++) {
e0018b
 		if (strcmp(argv[i], "all") == 0) {
e0018b
-			argv[0] = "all";
e0018b
 			argc = 1;
e0018b
 			break;
e0018b
 		}
e0018b
+		if (sscanf(argv[i], "mem%lu", &id) == 1)
e0018b
+			continue;
e0018b
+		if (sscanf(argv[i], "%lu", &id) == 1)
e0018b
+			continue;
e0018b
 
e0018b
-		if (sscanf(argv[i], "mem%lu", &id) != 1) {
e0018b
-			log_err(&ml, "'%s' is not a valid memdev name\n",
e0018b
-				argv[i]);
e0018b
-			err++;
e0018b
-		}
e0018b
+		log_err(&ml, "'%s' is not a valid memdev name\n", argv[i]);
e0018b
+		err++;
e0018b
 	}
e0018b
 
e0018b
 	if (err == argc) {
e0018b
@@ -243,11 +243,7 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
e0018b
 	count = 0;
e0018b
 
e0018b
 	for (i = 0; i < argc; i++) {
e0018b
-		if (sscanf(argv[i], "mem%lu", &id) != 1
e0018b
-				&& strcmp(argv[i], "all") != 0)
e0018b
-			continue;
e0018b
-
e0018b
-		cxl_memdev_foreach (ctx, memdev) {
e0018b
+		cxl_memdev_foreach(ctx, memdev) {
e0018b
 			if (!util_cxl_memdev_filter(memdev, argv[i], NULL))
e0018b
 				continue;
e0018b
 
e0018b
-- 
e0018b
2.27.0
e0018b