diff mbox

[ndctl,1/2] ndctl, util: cleanup filter-by-dimm helpers

Message ID 150256590603.13073.16819489053604962816.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit b05f821a7dee
Headers show

Commit Message

Dan Williams Aug. 12, 2017, 7:25 p.m. UTC
Use util_dimm_filter() as a helper for these 'filter_by' routines.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 util/filter.c |   37 ++++---------------------------------
 1 file changed, 4 insertions(+), 33 deletions(-)
diff mbox

Patch

diff --git a/util/filter.c b/util/filter.c
index 93d56928a3dc..400c11a3a80a 100644
--- a/util/filter.c
+++ b/util/filter.c
@@ -119,57 +119,28 @@  struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, const char *ident)
 struct ndctl_bus *util_bus_filter_by_dimm(struct ndctl_bus *bus,
 		const char *ident)
 {
-	char *end = NULL;
-	const char *name;
 	struct ndctl_dimm *dimm;
-	unsigned long dimm_id, id;
 
 	if (!ident || strcmp(ident, "all") == 0)
 		return bus;
 
-	dimm_id = strtoul(ident, &end, 0);
-	if (end == ident || end[0])
-		dimm_id = ULONG_MAX;
-
-	ndctl_dimm_foreach(bus, dimm) {
-		id = ndctl_dimm_get_id(dimm);
-		name = ndctl_dimm_get_devname(dimm);
-
-		if (dimm_id < ULONG_MAX && dimm_id == id)
+	ndctl_dimm_foreach(bus, dimm)
+		if (util_dimm_filter(dimm, ident))
 			return bus;
-
-		if (dimm_id == ULONG_MAX && strcmp(ident, name) == 0)
-			return bus;
-	}
-
 	return NULL;
 }
 
 struct ndctl_region *util_region_filter_by_dimm(struct ndctl_region *region,
 		const char *ident)
 {
-	char *end = NULL;
-	const char *name;
 	struct ndctl_dimm *dimm;
-	unsigned long dimm_id, id;
 
 	if (!ident || strcmp(ident, "all") == 0)
 		return region;
 
-	dimm_id = strtoul(ident, &end, 0);
-	if (end == ident || end[0])
-		dimm_id = ULONG_MAX;
-
-	ndctl_dimm_foreach_in_region(region, dimm) {
-		id = ndctl_dimm_get_id(dimm);
-		name = ndctl_dimm_get_devname(dimm);
-
-		if (dimm_id < ULONG_MAX && dimm_id == id)
-			return region;
-
-		if (dimm_id == ULONG_MAX && strcmp(ident, name) == 0)
+	ndctl_dimm_foreach_in_region(region, dimm)
+		if (util_dimm_filter(dimm, ident))
 			return region;
-	}
 
 	return NULL;
 }