All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 5/7] ndctl: fix to_dsm_index() static analysis warning
Date: Mon, 25 Apr 2016 12:50:15 -0700	[thread overview]
Message-ID: <146161381575.21779.8108705781017518591.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <146161378966.21779.1219526957524644729.stgit@dwillia2-desk3.amr.corp.intel.com>

Static analysis tools don't like the fact that we do multiple
overwriting assignments to a variable.  Use IS_ENABLED() to clean this
up.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 lib/libndctl-private.h |   15 +++++++++++++++
 lib/libndctl.c         |   10 +++-------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/lib/libndctl-private.h b/lib/libndctl-private.h
index cbb0ed9f76b5..a0a36885b160 100644
--- a/lib/libndctl-private.h
+++ b/lib/libndctl-private.h
@@ -177,6 +177,21 @@ struct ndctl_cmd {
 	};
 };
 
+/* internal library helpers for conditionally defined command numbers */
+#ifdef HAVE_NDCTL_ARS
+static const int nd_cmd_ars_status = ND_CMD_ARS_STATUS;
+static const int nd_cmd_ars_cap = ND_CMD_ARS_CAP;
+#else
+static const int nd_cmd_ars_status;
+static const int nd_cmd_ars_cap;
+#endif
+
+#ifdef HAVE_NDCTL_CLEAR_ERROR
+static const int nd_cmd_clear_error = ND_CMD_CLEAR_ERROR;
+#else
+static const int nd_cmd_clear_error;
+#endif
+
 static inline struct ndctl_bus *cmd_to_bus(struct ndctl_cmd *cmd)
 {
 	if (cmd->dimm)
diff --git a/lib/libndctl.c b/lib/libndctl.c
index 1014da2aa8a9..5c2894d6b82e 100644
--- a/lib/libndctl.c
+++ b/lib/libndctl.c
@@ -813,13 +813,9 @@ static int to_dsm_index(const char *name, int dimm)
 		end_cmd = ND_CMD_VENDOR;
 		cmd_name_fn = nvdimm_cmd_name;
 	} else {
-		end_cmd = 0;
-#ifdef HAVE_NDCTL_ARS
-		end_cmd = ND_CMD_ARS_STATUS;
-#endif
-#ifdef HAVE_NDCTL_CLEAR_ERROR
-		end_cmd = ND_CMD_CLEAR_ERROR;
-#endif
+		end_cmd = nd_cmd_clear_error;
+		if (!end_cmd)
+			end_cmd = nd_cmd_ars_status;
 		cmd_name_fn = nvdimm_bus_cmd_name;
 	}
 

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

  parent reply	other threads:[~2016-04-25 19:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-25 19:49 [ndctl PATCH 0/7] miscellaneous fixes Dan Williams
2016-04-25 19:49 ` [ndctl PATCH 1/7] ndctl, create-namespace: report failures due to namespace being mounted Dan Williams
2016-04-25 19:49 ` [ndctl PATCH 2/7] ndctl, create-namespace: check for ZONE_DEVICE=n kernels Dan Williams
2016-04-25 19:50 ` [ndctl PATCH 3/7] ndctl: fix some warnings Dan Williams
2016-04-25 19:50 ` [ndctl PATCH 4/7] ndctl: drop asciidocs and xmlto requirement for --disable-docs Dan Williams
2016-04-25 19:50 ` Dan Williams [this message]
2016-04-26 18:10   ` [ndctl PATCH 5/7] ndctl: fix to_dsm_index() static analysis warning Dan Williams
2016-04-25 19:50 ` [ndctl PATCH 6/7] ndctl: fix uninitialized variable in add_dimm() Dan Williams
2016-04-25 19:50 ` [ndctl PATCH 7/7] ndctl: fix unchecked return value Dan Williams

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=146161381575.21779.8108705781017518591.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    /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.