]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
UAPI: ndctl: Fix g++-unsupported initialisation in headers
authorDavid Howells <dhowells@redhat.com>
Thu, 6 Sep 2018 09:19:24 +0000 (10:19 +0100)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:56:45 +0000 (19:56 -0600)
commit56d86450f4f43b3204d824031f96217c04672d92
tree782becfee8a5c7b7d8b4d671b1a91df8e88bd68a
parentac9da72d259c35abb119e5af7845c9896df93821
UAPI: ndctl: Fix g++-unsupported initialisation in headers

BugLink: https://bugs.launchpad.net/bugs/1836802
[ Upstream commit 9607871f37dc3e717639694b8d0dc738f2a68efc ]

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>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
include/uapi/linux/ndctl.h