All of lore.kernel.org
 help / color / mirror / Atom feed
From: 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>
Subject: [dm-devel] [PATCH 04/11] libmultipath: use ARRAY_SIZE for iterating over wildcard arrays
Date: Sat, 27 Nov 2021 16:19:59 +0100	[thread overview]
Message-ID: <20211127152006.8035-5-mwilck@suse.com> (raw)
In-Reply-To: <20211127152006.8035-1-mwilck@suse.com>

From: Martin Wilck <mwilck@suse.com>

Avoid the extra empty element at the end of the array, and use the
ARRAY_SIZE paradigm that we've adopted elsewhere in multipath-tools.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/print.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/libmultipath/print.c b/libmultipath/print.c
index 37222bf..fcbaa5a 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -817,7 +817,6 @@ static struct multipath_data mpd[] = {
 	{'e', "rev",           0, snprint_multipath_rev},
 	{'G', "foreign",       0, snprint_multipath_foreign},
 	{'g', "vpd page data", 0, snprint_multipath_vpd_data},
-	{0, NULL, 0 , NULL}
 };
 
 static struct path_data pd[] = {
@@ -846,7 +845,6 @@ static struct path_data pd[] = {
 	{'0', "failures",      0, snprint_path_failures},
 	{'P', "protocol",      0, snprint_path_protocol},
 	{'I', "init_st",       0, snprint_initialized},
-	{0, NULL, 0 , NULL}
 };
 
 static struct pathgroup_data pgd[] = {
@@ -854,31 +852,31 @@ static struct pathgroup_data pgd[] = {
 	{'p', "pri",           0, snprint_pg_pri},
 	{'t', "dm_st",         0, snprint_pg_state},
 	{'M', "marginal_st",   0, snprint_pg_marginal},
-	{0, NULL, 0 , NULL}
 };
 
 int snprint_wildcards(struct strbuf *buff)
 {
 	int initial_len = get_strbuf_len(buff);
-	int i, rc;
+	unsigned int i;
+	int rc;
 
 	if ((rc = append_strbuf_str(buff, "multipath format wildcards:\n")) < 0)
 		return rc;
-	for (i = 0; mpd[i].header; i++)
+	for (i = 0; i < ARRAY_SIZE(mpd); i++)
 		if ((rc = print_strbuf(buff, "%%%c  %s\n",
 				       mpd[i].wildcard, mpd[i].header)) < 0)
 			return rc;
 
 	if ((rc = append_strbuf_str(buff, "\npath format wildcards:\n")) < 0)
 		return rc;
-	for (i = 0; pd[i].header; i++)
+	for (i = 0; i < ARRAY_SIZE(pd); i++)
 		if ((rc = print_strbuf(buff, "%%%c  %s\n",
 				       pd[i].wildcard, pd[i].header)) < 0)
 			return rc;
 
 	if ((rc = append_strbuf_str(buff, "\npathgroup format wildcards:\n")) < 0)
 		return rc;
-	for (i = 0; pgd[i].header; i++)
+	for (i = 0; i < ARRAY_SIZE(pgd); i++)
 		if ((rc = print_strbuf(buff, "%%%c  %s\n",
 				       pgd[i].wildcard, pgd[i].header)) < 0)
 			return rc;
@@ -915,10 +913,10 @@ reset_width(unsigned int *width, enum layout_reset reset, const char *header)
 void
 _get_path_layout (const struct _vector *gpvec, enum layout_reset reset)
 {
-	int i, j;
+	unsigned int i, j;
 	const struct gen_path *gp;
 
-	for (j = 0; pd[j].header; j++) {
+        for (j = 0; j < ARRAY_SIZE(pd); j++) {
 		STRBUF_ON_STACK(buff);
 
 		reset_width(&pd[j].width, reset, pd[j].header);
@@ -937,9 +935,9 @@ _get_path_layout (const struct _vector *gpvec, enum layout_reset reset)
 static void
 reset_multipath_layout (void)
 {
-	int i;
+	unsigned int i;
 
-	for (i = 0; mpd[i].header; i++)
+	for (i = 0; i < ARRAY_SIZE(mpd); i++)
 		mpd[i].width = 0;
 }
 
@@ -956,10 +954,10 @@ void
 _get_multipath_layout (const struct _vector *gmvec,
 			    enum layout_reset reset)
 {
-	int i, j;
+	unsigned int i, j;
 	const struct gen_multipath * gm;
 
-	for (j = 0; mpd[j].header; j++) {
+	for (j = 0; j < ARRAY_SIZE(mpd); j++) {
 		STRBUF_ON_STACK(buff);
 
 		reset_width(&mpd[j].width, reset, mpd[j].header);
@@ -978,9 +976,9 @@ _get_multipath_layout (const struct _vector *gmvec,
 
 static int mpd_lookup(char wildcard)
 {
-	int i;
+	unsigned int i;
 
-	for (i = 0; mpd[i].header; i++)
+	for (i = 0; i < ARRAY_SIZE(mpd); i++)
 		if (mpd[i].wildcard == wildcard)
 			return i;
 
@@ -1000,9 +998,9 @@ int snprint_multipath_attr(const struct gen_multipath* gm,
 
 static int pd_lookup(char wildcard)
 {
-	int i;
+	unsigned int i;
 
-	for (i = 0; pd[i].header; i++)
+	for (i = 0; i < ARRAY_SIZE(pd); i++)
 		if (pd[i].wildcard == wildcard)
 			return i;
 
@@ -1022,9 +1020,9 @@ int snprint_path_attr(const struct gen_path* gp,
 
 static int pgd_lookup(char wildcard)
 {
-	int i;
+	unsigned int i;
 
-	for (i = 0; pgd[i].header; i++)
+	for (i = 0; i < ARRAY_SIZE(pgd); i++)
 		if (pgd[i].wildcard == wildcard)
 			return i;
 
-- 
2.33.1


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


  parent reply	other threads:[~2021-11-27 15:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-27 15:19 [dm-devel] [PATCH 00/11] multipath-tools: improvements for pretty-printing code mwilck
2021-11-27 15:19 ` [dm-devel] [PATCH 01/11] libmultipath: make multipath_data etc. static mwilck
2021-11-27 15:19 ` [dm-devel] [PATCH 02/11] libmultipath: move path_data etc. to print.c mwilck
2021-11-27 15:19 ` [dm-devel] [PATCH 03/11] libmultipath: make pd_lookup() etc. return an index mwilck
2021-11-27 15:19 ` mwilck [this message]
2021-11-27 15:20 ` [dm-devel] [PATCH 05/11] libmultipath: drop padding code in _snprint_pathgroup() mwilck
2021-11-27 15:20 ` [dm-devel] [PATCH 06/11] libmultipath: snprint_foreign_topology(): split out lockless variant mwilck
2021-11-27 15:20 ` [dm-devel] [PATCH 07/11] multipathd: drop unnecessary path layout calls mwilck
2021-11-27 15:20 ` [dm-devel] [PATCH 08/11] libmultipath: add a cleanup function for unsigned char * mwilck
2021-11-27 15:20 ` [dm-devel] [PATCH 09/11] libmultipath: make sprint_path_marginal() static mwilck
2021-11-27 15:20 ` [dm-devel] [PATCH 10/11] libmultipath: introduce width argument for pretty-printing functions mwilck
2021-11-27 15:20 ` [dm-devel] [PATCH 11/11] libmultipath: change wildcard handler tables to static const mwilck

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=20211127152006.8035-5-mwilck@suse.com \
    --to=mwilck@suse.com \
    --cc=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.