libmultipath: tidy up do_set_from_hwe() with statement expression
authorMartin Wilck <mwilck@suse.com>
Mon, 18 Mar 2019 11:24:43 +0000 (12:24 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Thu, 18 Apr 2019 11:07:31 +0000 (13:07 +0200)
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@suse.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
libmultipath/propsel.c

index 27474f0..caf55b6 100644 (file)
@@ -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[] =