/[packages]/cauldron/kernel/current/PATCHES/patches/0093-UAPI-ndctl-Fix-g-unsupported-initialisation-in-heade.patch
ViewVC logotype

Contents of /cauldron/kernel/current/PATCHES/patches/0093-UAPI-ndctl-Fix-g-unsupported-initialisation-in-heade.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1329221 - (show annotations) (download)
Fri Nov 9 22:05:45 2018 UTC (5 years, 10 months ago) by tmb
File size: 3648 byte(s)
add fixes from sashas autosel queue
1 From 60407a54f520212587ddcd6f91a9c68ce8e56619 Mon Sep 17 00:00:00 2001
2 From: David Howells <dhowells@redhat.com>
3 Date: Thu, 6 Sep 2018 10:19:24 +0100
4 Subject: [PATCH 093/145] UAPI: ndctl: Fix g++-unsupported initialisation in
5 headers
6
7 [ Upstream commit 9607871f37dc3e717639694b8d0dc738f2a68efc ]
8
9 The following code in the linux/ndctl header file:
10
11 static inline const char *nvdimm_bus_cmd_name(unsigned cmd)
12 {
13 static const char * const names[] = {
14 [ND_CMD_ARS_CAP] = "ars_cap",
15 [ND_CMD_ARS_START] = "ars_start",
16 [ND_CMD_ARS_STATUS] = "ars_status",
17 [ND_CMD_CLEAR_ERROR] = "clear_error",
18 [ND_CMD_CALL] = "cmd_call",
19 };
20
21 if (cmd < ARRAY_SIZE(names) && names[cmd])
22 return names[cmd];
23 return "unknown";
24 }
25
26 is broken in a number of ways:
27
28 (1) ARRAY_SIZE() is not generally defined.
29
30 (2) g++ does not support "non-trivial" array initialisers fully yet.
31
32 (3) Every file that calls this function will acquire a copy of names[].
33
34 The same goes for nvdimm_cmd_name().
35
36 Fix all three by converting to a switch statement where each case returns a
37 string. That way if cmd is a constant, the compiler can trivially reduce it
38 and, if not, the compiler can use a shared lookup table if it thinks that is
39 more efficient.
40
41 A better way would be to remove these functions and their arrays from the
42 header entirely.
43
44 Signed-off-by: David Howells <dhowells@redhat.com>
45 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
46 Signed-off-by: Sasha Levin <sashal@kernel.org>
47 ---
48 include/uapi/linux/ndctl.h | 48 +++++++++++++++++---------------------
49 1 file changed, 21 insertions(+), 27 deletions(-)
50
51 diff --git a/include/uapi/linux/ndctl.h b/include/uapi/linux/ndctl.h
52 index 7e27070b9440..2f2c43d633c5 100644
53 --- a/include/uapi/linux/ndctl.h
54 +++ b/include/uapi/linux/ndctl.h
55 @@ -128,37 +128,31 @@ enum {
56
57 static inline const char *nvdimm_bus_cmd_name(unsigned cmd)
58 {
59 - static const char * const names[] = {
60 - [ND_CMD_ARS_CAP] = "ars_cap",
61 - [ND_CMD_ARS_START] = "ars_start",
62 - [ND_CMD_ARS_STATUS] = "ars_status",
63 - [ND_CMD_CLEAR_ERROR] = "clear_error",
64 - [ND_CMD_CALL] = "cmd_call",
65 - };
66 -
67 - if (cmd < ARRAY_SIZE(names) && names[cmd])
68 - return names[cmd];
69 - return "unknown";
70 + switch (cmd) {
71 + case ND_CMD_ARS_CAP: return "ars_cap";
72 + case ND_CMD_ARS_START: return "ars_start";
73 + case ND_CMD_ARS_STATUS: return "ars_status";
74 + case ND_CMD_CLEAR_ERROR: return "clear_error";
75 + case ND_CMD_CALL: return "cmd_call";
76 + default: return "unknown";
77 + }
78 }
79
80 static inline const char *nvdimm_cmd_name(unsigned cmd)
81 {
82 - static const char * const names[] = {
83 - [ND_CMD_SMART] = "smart",
84 - [ND_CMD_SMART_THRESHOLD] = "smart_thresh",
85 - [ND_CMD_DIMM_FLAGS] = "flags",
86 - [ND_CMD_GET_CONFIG_SIZE] = "get_size",
87 - [ND_CMD_GET_CONFIG_DATA] = "get_data",
88 - [ND_CMD_SET_CONFIG_DATA] = "set_data",
89 - [ND_CMD_VENDOR_EFFECT_LOG_SIZE] = "effect_size",
90 - [ND_CMD_VENDOR_EFFECT_LOG] = "effect_log",
91 - [ND_CMD_VENDOR] = "vendor",
92 - [ND_CMD_CALL] = "cmd_call",
93 - };
94 -
95 - if (cmd < ARRAY_SIZE(names) && names[cmd])
96 - return names[cmd];
97 - return "unknown";
98 + switch (cmd) {
99 + case ND_CMD_SMART: return "smart";
100 + case ND_CMD_SMART_THRESHOLD: return "smart_thresh";
101 + case ND_CMD_DIMM_FLAGS: return "flags";
102 + case ND_CMD_GET_CONFIG_SIZE: return "get_size";
103 + case ND_CMD_GET_CONFIG_DATA: return "get_data";
104 + case ND_CMD_SET_CONFIG_DATA: return "set_data";
105 + case ND_CMD_VENDOR_EFFECT_LOG_SIZE: return "effect_size";
106 + case ND_CMD_VENDOR_EFFECT_LOG: return "effect_log";
107 + case ND_CMD_VENDOR: return "vendor";
108 + case ND_CMD_CALL: return "cmd_call";
109 + default: return "unknown";
110 + }
111 }
112
113 #define ND_IOCTL 'N'
114 --
115 2.19.1
116

  ViewVC Help
Powered by ViewVC 1.1.30