]> www.infradead.org Git - users/mchehab/edac.git/commitdiff
edac: replace mc_event_error_type() by a define ghes_v5
authorMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 26 Feb 2013 13:18:35 +0000 (10:18 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 26 Feb 2013 14:22:40 +0000 (11:22 -0300)
While this works properly inside the Kernel, when a perf
userspace tries to parse the ras:mc_event, it will fail
with:
function mc_event_error_type not defined

That happens because this inline function doesn't exist in
userspace.

Replace it by a define, to avoid the userspace error as a
workaround.

This is the second trial of this workaround. On the first
trial attempt, a logic similar to this was used:

+#define mc_event_error_type(err_type)                  \
+({                                                     \
+       char *__mc_event_err_type;                      \
+       switch (err_type) {                             \
+       case HW_EVENT_ERR_CORRECTED:                    \
+               __mc_event_err_type = "Corrected";      \
+               break;                                  \
...
+       __mc_event_err_type;                            \
+})

The above failed, as the trace-cmd parsing library complained
with regards to the {} block there.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
include/linux/edac.h

index 4fd4999ccb5bf3386db3c27fec3f0f1d4a048b42..f9c14842398092538377cbf7b0a022c4a5623d9b 100644 (file)
@@ -112,20 +112,25 @@ enum hw_event_mc_err_type {
        HW_EVENT_ERR_INFO,
 };
 
-static inline char *mc_event_error_type(const unsigned int err_type)
-{
-       switch (err_type) {
-       case HW_EVENT_ERR_CORRECTED:
-               return "Corrected";
-       case HW_EVENT_ERR_UNCORRECTED:
-               return "Uncorrected";
-       case HW_EVENT_ERR_FATAL:
-               return "Fatal";
-       default:
-       case HW_EVENT_ERR_INFO:
-               return "Info";
-       }
-}
+/*
+ * Convert from hw_event_mc_err_type into an string.
+ *
+ * As this macro is used on trace, and userspace uses the format
+ * definition at [DEBUGFS]/tracing/events/ras/mc_event/format,
+ * the syntax used here should be very pedantic, otherwise userspace
+ * won't be able to parse it. Based on previous tests, no inline
+ * functions nor {} blocks are allowed here. Thankfully, there's
+ * now only 4 types of errors, so, still not so big to make impossible
+ * to use this kind of conditional logic.
+ */
+#define mc_event_error_type(err_type)                          \
+( (err_type) == HW_EVENT_ERR_CORRECTED ? "Corrected" :         \
+  ( (err_type) == HW_EVENT_ERR_UNCORRECTED ? "Uncorrected" :   \
+    ( (err_type) == HW_EVENT_ERR_FATAL ? "Fatal" :             \
+      "Info"                                                   \
+    )                                                          \
+  )                                                            \
+)
 
 /**
  * enum mem_type - memory types. For a more detailed reference, please see