[PATCH v3 08/10] libmultipath: tidy up do_set_from_hwe() with statement expression

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



propsel.c has a lot of "funky" macros making assumptions about
variable and label names in callers. This one is particularly
ugly. As a first tidy-up step, split out a statement expression
which can be called cleanly from code that doesn't have said
variables and labels.

Cc: Hannes Reinecke <hare@xxxxxxxx>
Signed-off-by: Martin Wilck <mwilck@xxxxxxxx>
---
 libmultipath/propsel.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
index 27474f05..caf55b68 100644
--- a/libmultipath/propsel.c
+++ b/libmultipath/propsel.c
@@ -45,22 +45,30 @@ do {									\
 	}								\
 } while(0)
 
-#define do_set_from_vec(type, var, src, dest, msg)			\
-do {									\
+#define __do_set_from_vec(type, var, src, dest)				\
+({									\
 	type *_p;							\
+	bool _found = false;						\
 	int i;								\
 									\
 	vector_foreach_slot(src, _p, i) {				\
 		if (_p->var) {						\
 			dest = _p->var;					\
-			origin = msg;					\
-			goto out;					\
+			_found = true;					\
+			break;						\
 		}							\
 	}								\
-} while (0)
+	_found;								\
+})
+
+#define __do_set_from_hwe(var, src, dest) \
+	__do_set_from_vec(struct hwentry, var, (src)->hwe, dest)
 
-#define do_set_from_hwe(var, src, dest, msg) \
-	do_set_from_vec(struct hwentry, var, src->hwe, dest, msg)
+#define do_set_from_hwe(var, src, dest, msg)				\
+	if (__do_set_from_hwe(var, src, dest)) {			\
+		origin = msg;						\
+		goto out;						\
+	}
 
 static const char default_origin[] = "(setting: multipath internal)";
 static const char hwe_origin[] =
-- 
2.21.0

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel



[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux