Blame SOURCES/0139-daxctl-provide-safe-versions-of-iteration-API.patch

e0018b
From 3e4a66f0dfb02046f6d3375d637840b6da9c71d1 Mon Sep 17 00:00:00 2001
e0018b
From: michalbiesek <michal.biesek@intel.com>
e0018b
Date: Mon, 2 Dec 2019 11:21:03 +0100
e0018b
Subject: [PATCH 139/217] daxctl: provide safe versions of iteration API
e0018b
e0018b
Add support for safe iterate through regions and devices
e0018b
e0018b
Link: https://github.com/pmem/ndctl/pull/132
e0018b
Signed-off-by: Michal Biesek <michal.biesek@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 daxctl/libdaxctl.h | 13 +++++++++++++
e0018b
 1 file changed, 13 insertions(+)
e0018b
e0018b
diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h
e0018b
index 6b6c71f..6876037 100644
e0018b
--- a/daxctl/libdaxctl.h
e0018b
+++ b/daxctl/libdaxctl.h
e0018b
@@ -93,12 +93,25 @@ int daxctl_memory_online_no_movable(struct daxctl_memory *mem);
e0018b
              dev != NULL; \
e0018b
              dev = daxctl_dev_get_next(dev))
e0018b
 
e0018b
+#define daxctl_dev_foreach_safe(region, dev, _dev) \
e0018b
+        for (dev = daxctl_dev_get_first(region), \
e0018b
+             _dev = dev ? daxctl_dev_get_next(dev) : NULL; \
e0018b
+             dev != NULL; \
e0018b
+             dev = _dev, \
e0018b
+            _dev = _dev ? daxctl_dev_get_next(_dev) : NULL)
e0018b
 
e0018b
 #define daxctl_region_foreach(ctx, region) \
e0018b
         for (region = daxctl_region_get_first(ctx); \
e0018b
              region != NULL; \
e0018b
              region = daxctl_region_get_next(region))
e0018b
 
e0018b
+#define daxctl_region_foreach_safe(ctx, region, _region) \
e0018b
+        for (region = daxctl_region_get_first(ctx), \
e0018b
+             _region = region ? daxctl_region_get_next(region) : NULL; \
e0018b
+             region != NULL; \
e0018b
+             region = _region, \
e0018b
+            _region = _region ? daxctl_region_get_next(_region) : NULL)
e0018b
+
e0018b
 struct daxctl_mapping;
e0018b
 struct daxctl_mapping *daxctl_mapping_get_first(struct daxctl_dev *dev);
e0018b
 struct daxctl_mapping *daxctl_mapping_get_next(struct daxctl_mapping *mapping);
e0018b
-- 
e0018b
2.27.0
e0018b