nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: David Howells <dhowells@redhat.com>
Cc: Linux API <linux-api@vger.kernel.org>,
	linux-nvdimm <linux-nvdimm@lists.01.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-kbuild@vger.kernel.org
Subject: Re: [PATCH 09/11] UAPI: ndctl: Fix g++-unsupported initialisation in headers [ver #2]
Date: Tue, 25 Sep 2018 13:22:21 -0700	[thread overview]
Message-ID: <CAPcyv4jjxh955mWEubnGiENVQVeCcZ9YWv8YPBKfWMw-gh1z2w@mail.gmail.com> (raw)
In-Reply-To: <153622556444.14298.5971956747198405225.stgit@warthog.procyon.org.uk>

On Thu, Sep 6, 2018 at 2:19 AM David Howells <dhowells@redhat.com> wrote:
>
> 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.
>
>  (2) g++ does not support "non-trivial" array initialisers fully yet.
>
>  (3) Every file that calls this function will acquire a copy of names[].
>
> The same goes for nvdimm_cmd_name().
>
> Fix all three by converting to a switch statement where each case returns a
> string.  That way if cmd is a constant, the compiler can trivially reduce it
> and, if not, the compiler can use a shared lookup table if it thinks that is
> more efficient.
>
> 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>

Acked-by: Dan Williams <dan.j.williams@intel.com>

...again let me know if you'll take this with g++ series or want me to
carry it directly.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

  reply	other threads:[~2018-09-25 20:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-06  9:18 [RFC] UAPI: Check headers by compiling all together as C++ David Howells
2018-09-06  9:19 ` [PATCH 09/11] UAPI: ndctl: Fix g++-unsupported initialisation in headers [ver #2] David Howells
2018-09-25 20:22   ` Dan Williams [this message]
2018-09-06  9:19 ` [PATCH 10/11] UAPI: ndctl: Remove use of PAGE_SIZE " David Howells
2018-09-25 20:17   ` Dan Williams
2018-10-09 15:36   ` David Howells

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=CAPcyv4jjxh955mWEubnGiENVQVeCcZ9YWv8YPBKfWMw-gh1z2w@mail.gmail.com \
    --to=dan.j.williams@intel.com \
    --cc=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 \
    /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;
as well as URLs for NNTP newsgroup(s).