Linux Device Mapper development
 help / color / mirror / Atom feed
From: Martin Wilck <mwilck@suse.com>
To: Christophe Varoqui <christophe.varoqui@opensvc.com>,
	Benjamin Marzinski <bmarzins@redhat.com>
Cc: dm-devel@redhat.com, Martin Wilck <mwilck@suse.com>,
	Hannes Reinecke <hare@suse.com>
Subject: [PATCH v3 08/10] libmultipath: tidy up do_set_from_hwe() with statement expression
Date: Mon, 18 Mar 2019 12:24:43 +0100	[thread overview]
Message-ID: <20190318112445.6636-9-mwilck@suse.com> (raw)
In-Reply-To: <20190318112445.6636-1-mwilck@suse.com>

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 | 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

  parent reply	other threads:[~2019-03-18 11:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18 11:24 [PATCH v3 00/10] multipath-tools: avoid I/O during uevent processing Martin Wilck
2019-03-18 11:24 ` [PATCH v3 01/10] libmultipath: add sysfs_get_inquiry() Martin Wilck
2019-03-18 11:24 ` [PATCH v3 02/10] libmultipath: alua: make API more consistent Martin Wilck
2019-03-18 11:24 ` [PATCH v3 03/10] libmultipath: alua: try to retrieve inquiry data from sysfs Martin Wilck
2019-03-18 11:24 ` [PATCH v3 04/10] libmultipath: constify sysfs_get_timeout() Martin Wilck
2019-03-18 11:24 ` [PATCH v3 05/10] libmultipath: detect_alua(): use system timeout Martin Wilck
2019-03-19 18:36   ` Benjamin Marzinski
2019-03-18 11:24 ` [PATCH v3 06/10] libmultipath: lazy tpgs probing Martin Wilck
2019-03-18 11:24 ` [PATCH v3 07/10] libmultipath: don't link alua_rtpg.o twice Martin Wilck
2019-03-18 11:24 ` Martin Wilck [this message]
2019-03-18 11:24 ` [PATCH v3 09/10] libmultipath: check_rdac(): pre-check in hwtable Martin Wilck
2019-03-18 11:24 ` [PATCH v3 10/10] libmultipath: hwtable: add Lenovo DE series Martin Wilck
2019-03-18 17:28   ` Schremmer, Steven
2019-04-12 17:27     ` Schremmer, Steven
2019-03-19 18:37 ` [PATCH v3 00/10] multipath-tools: avoid I/O during uevent processing Benjamin Marzinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190318112445.6636-9-mwilck@suse.com \
    --to=mwilck@suse.com \
    --cc=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.com \
    --cc=hare@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox