From: David Howells <dhowells@redhat.com> To: linux-api@vger.kernel.org, linux-kbuild@vger.kernel.org Cc: dhowells@redhat.com, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [PATCH 09/11] UAPI: ndctl: Fix g++-unsupported initialisation in headers Date: Wed, 05 Sep 2018 16:55:37 +0100 [thread overview] Message-ID: <153616293757.23468.13765050528392604035.stgit@warthog.procyon.org.uk> (raw) In-Reply-To: <153616286704.23468.584491117180383924.stgit@warthog.procyon.org.uk> The following code in the linux/ndctl header file: static inline const char *nvdimm_bus_cmd_name(unsigned cmd) { static const char * const names[] = { [ND_CMD_ARS_CAP] = "ars_cap", [ND_CMD_ARS_START] = "ars_start", [ND_CMD_ARS_STATUS] = "ars_status", [ND_CMD_CLEAR_ERROR] = "clear_error", [ND_CMD_CALL] = "cmd_call", }; if (cmd < ARRAY_SIZE(names) && names[cmd]) return names[cmd]; return "unknown"; } is broken in a number of ways: (1) ARRAY_SIZE() is not generally defined. Fix this by defining a label in the enum that indicates the number of commands. (2) g++ does not support "non-trivial" array initialisers fully yet. Fix this by defining the missing intermediate values. (3) Every file that calls this function will acquire a copy of names[]. The same goes for nvdimm_cmd_name(). A better way would be to remove these functions and their arrays from the header entirely. Signed-off-by: David Howells <dhowells@redhat.com> cc: Dan Williams <dan.j.williams@intel.com> cc: linux-nvdimm@lists.01.org --- include/uapi/linux/ndctl.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/ndctl.h b/include/uapi/linux/ndctl.h index 7e27070b9440..9c89159f6a0f 100644 --- a/include/uapi/linux/ndctl.h +++ b/include/uapi/linux/ndctl.h @@ -117,6 +117,7 @@ enum { ND_CMD_VENDOR_EFFECT_LOG = 8, ND_CMD_VENDOR = 9, ND_CMD_CALL = 10, + nr__ND_CMD = 11 }; enum { @@ -128,22 +129,29 @@ enum { static inline const char *nvdimm_bus_cmd_name(unsigned cmd) { - static const char * const names[] = { + static const char * const names[nr__ND_CMD] = { + [0] = NULL, [ND_CMD_ARS_CAP] = "ars_cap", [ND_CMD_ARS_START] = "ars_start", [ND_CMD_ARS_STATUS] = "ars_status", [ND_CMD_CLEAR_ERROR] = "clear_error", + [5] = NULL, + [6] = NULL, + [7] = NULL, + [8] = NULL, + [9] = NULL, [ND_CMD_CALL] = "cmd_call", }; - if (cmd < ARRAY_SIZE(names) && names[cmd]) + if (cmd < nr__ND_CMD && names[cmd]) return names[cmd]; return "unknown"; } static inline const char *nvdimm_cmd_name(unsigned cmd) { - static const char * const names[] = { + static const char * const names[nr__ND_CMD] = { + [0] = NULL, [ND_CMD_SMART] = "smart", [ND_CMD_SMART_THRESHOLD] = "smart_thresh", [ND_CMD_DIMM_FLAGS] = "flags", @@ -156,7 +164,7 @@ static inline const char *nvdimm_cmd_name(unsigned cmd) [ND_CMD_CALL] = "cmd_call", }; - if (cmd < ARRAY_SIZE(names) && names[cmd]) + if (cmd < nr__ND_CMD && names[cmd]) return names[cmd]; return "unknown"; } _______________________________________________ Linux-nvdimm mailing list Linux-nvdimm@lists.01.org https://lists.01.org/mailman/listinfo/linux-nvdimm
next prev parent reply other threads:[~2018-09-05 15:55 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-09-05 15:54 [RFC] UAPI: Check headers by compiling all together as C++ David Howells 2018-09-05 15:55 ` David Howells [this message] 2018-09-05 15:55 ` [PATCH 10/11] UAPI: ndctl: Remove use of PAGE_SIZE David Howells 2018-09-05 16:55 ` [RFC] UAPI: Check headers by compiling all together as C++ Greg KH 2018-09-05 17:33 ` Yann Droneaud 2018-09-05 17:42 ` Michael S. Tsirkin 2018-09-06 7:12 ` Yann Droneaud 2018-09-05 19:22 ` Jan Engelhardt
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=153616293757.23468.13765050528392604035.stgit@warthog.procyon.org.uk \ --to=dhowells@redhat.com \ --cc=linux-api@vger.kernel.org \ --cc=linux-kbuild@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-nvdimm@lists.01.org \ --subject='Re: [PATCH 09/11] UAPI: ndctl: Fix g++-unsupported initialisation in headers' \ /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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).