]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
rasdaemon: move type macros to a separate header (types.h)
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 18 Jul 2024 08:43:17 +0000 (10:43 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 18 Jul 2024 09:12:08 +0000 (11:12 +0200)
That makes easier to use/maintain it, without needing to include
ras-record.h when all it is needed are common macros.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
26 files changed:
non-standard-ampere.c
non-standard-hisi_hip08.c
non-standard-hisilicon.c
non-standard-jaguarmicro.c
non-standard-yitian.c
ras-aer-handler.c
ras-arm-handler.c
ras-cxl-handler.c
ras-devlink-handler.c
ras-diskerror-handler.c
ras-events.c
ras-events.h
ras-extlog-handler.c
ras-logger.h
ras-mc-handler.c
ras-mce-handler.c
ras-memory-failure-handler.c
ras-non-standard-handler.c
ras-non-standard-handler.h
ras-page-isolation.h
ras-record.c
ras-record.h
ras-report.h
rasdaemon.c
rbtree.h
types.h [new file with mode: 0644]

index 0790323c9d9cd4a5423424be33e5edfc55d2323e..b96e5c2f77f4c1ca8b62b819a893afe98b40d082 100644 (file)
@@ -12,7 +12,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdbool.h>
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 #include "ras-non-standard-handler.h"
index d90c6bf08017e5d25a32160dc9ce0b3b9b6e22ca..4776832a2f44def59a3050df7275a42dab5ee477 100644 (file)
@@ -11,7 +11,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 #include "ras-non-standard-handler.h"
index 00388ec2e87f7893477c454ffa6e9599625318ee..3d9fc30dbbd2fc1a7e329e8ef91eb95d791b87ef 100644 (file)
@@ -11,7 +11,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 #include "non-standard-hisilicon.h"
index fb887d34c198b46c6e7cd0bedd7546395fe9e826..745b656425114acf88b822bcd2465231f8e6f492 100644 (file)
@@ -12,7 +12,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdbool.h>
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 #include "ras-non-standard-handler.h"
index daadb95ef340c607e109da9a584082898c173731..d3dae38d461b8675f845cd02ac5e890a82d29fbf 100644 (file)
@@ -12,7 +12,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdbool.h>
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 #include "ras-non-standard-handler.h"
index 43334a9b7eabeb94a084f2f4088033a8154f30f3..8cfc663e7f5d0e22e177437722f3de3a5c88b6dc 100644 (file)
@@ -21,7 +21,7 @@
 #include <unistd.h>
 #include <traceevent/kbuffer.h>
 #include "ras-aer-handler.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "bitfield.h"
 #include "ras-report.h"
index 01122f3a70c7522198062b797ff3623fb1d1854e..576474662d698b1bef7e5dd169c408cc681bbbd7 100644 (file)
@@ -17,7 +17,7 @@
 #include <unistd.h>
 #include <traceevent/kbuffer.h>
 #include "ras-arm-handler.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 #include "ras-non-standard-handler.h"
index cbad347cf31c3114c9a655ab9cef86b3694509b4..02942bd38a2bede6cfeff9c81a08ff42ffc4fee6 100644 (file)
@@ -18,8 +18,9 @@
 #include <unistd.h>
 #include <traceevent/kbuffer.h>
 #include "ras-cxl-handler.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
+#include "ras-record.h"
 #include "ras-report.h"
 #include <endian.h>
 
index e281cd00ff5f9ccb9e7dee990ad6cc2b05858ed9..dfe22722ab08bee7498570d857279f2744a43a68 100644 (file)
@@ -23,7 +23,7 @@
 #include <unistd.h>
 #include <traceevent/kbuffer.h>
 #include "ras-devlink-handler.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 
index 0fd27aec516f72ff01b164608c327d5788b828ce..527f7dd788f6ae3dc386436ec80c488850c55203 100644 (file)
@@ -27,7 +27,7 @@
 #include <sys/sysmacros.h>
 #include <traceevent/kbuffer.h>
 #include "ras-diskerror-handler.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 
index 89896a055312f159a615227f6cf157788644bea6..a2a37738c72e58b1df6eb1736e719bbc02d24e47 100644 (file)
@@ -45,6 +45,7 @@
 #include "ras-memory-failure-handler.h"
 #include "ras-non-standard-handler.h"
 #include "ras-page-isolation.h"
+#include "ras-events.h"
 #include "ras-record.h"
 #include "trigger.h"
 
index 75ca506f7710f866b5a8cdad984b9b8b8573ed4f..135219e77e1015756e741ce25ba7b92728374d77 100644 (file)
 #ifndef __RAS_EVENTS_H
 #define __RAS_EVENTS_H
 
-#include "ras-record.h"
-
 #include <pthread.h>
 #include <time.h>
 
-#define MAX_PATH 1024
-#define STR(x) #x
+#include "types.h"
 
 struct mce_priv;
+struct ras_mc_offline_event;
 
 enum {
        MC_EVENT,
index 6ffe9060b437be95cc063a1581cfc651c6e360b9..ba48f1165f91a398ff602ca4c2dda142e04a3883 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "ras-extlog-handler.h"
 #include "ras-logger.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-report.h"
 
 static char *err_type(int etype)
index dbf1cb0264ad9eb32d3cfb965600a98445265cfc..6afe41f5192f58c9983f88f281c2e650096d1f5a 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <syslog.h>
 
-#include "ras-record.h"
+#include "types.h"
 
 /*
  * Logging macros
index 5062f9f5b1445254fb33b1f4249884384cb55778..74d88509a47ee96426aa2919658a96cf9fe941ee 100644 (file)
@@ -27,7 +27,7 @@
 #include "ras-mc-handler.h"
 #include "ras-logger.h"
 #include "ras-page-isolation.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-report.h"
 #include "trigger.h"
 
index fc08988069176198e378008ef6e3d8e91b12c6c1..aaf766f70c077a7d885323082874a1ab67ed90d1 100644 (file)
@@ -26,7 +26,7 @@
 #include <traceevent/kbuffer.h>
 
 #include "ras-mce-handler.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 
index 562796147b363d434f12c9baefdac2f8ce621a5d..a93b03415f74a6f165db6e8160c29c9867a585af 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "ras-logger.h"
 #include "ras-memory-failure-handler.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-report.h"
 #include "trigger.h"
 
index 19dd0c97e96871fc53844221a85b2398a4ca02f1..887ab146d9c44cbfb520e3ebff2302d4b4072b5b 100644 (file)
@@ -18,7 +18,7 @@
 #include <unistd.h>
 #include <traceevent/kbuffer.h>
 #include "ras-non-standard-handler.h"
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 
index 913ce00480b7b4115b2e2ea3a74480289e27ff04..5c6746db774c82b349a0646a9754a7d3ebdfd697 100644 (file)
@@ -15,6 +15,7 @@
 #define __RAS_NON_STANDARD_HANDLER_H
 
 #include "ras-events.h"
+#include "ras-record.h"
 #include <traceevent/event-parse.h>
 
 struct ras_ns_ev_decoder {
index 7ccfca16a048978f7f01484519476b9f24375627..7da68c0e7777f628615e828096488150501cc259 100644 (file)
@@ -18,7 +18,7 @@
 #include <stdbool.h>
 #include <time.h>
 
-#include "ras-record.h"
+#include "types.h"
 #include "rbtree.h"
 
 #define PAGE_SHIFT             12
index 8341ae817e487f127f6611412f947d8d248e5a28..e3631377f794878bde94ae1a5e085c56df6a507b 100644 (file)
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include "ras-events.h"
+#include "ras-record.h"
 #include "ras-mc-handler.h"
 #include "ras-aer-handler.h"
 #include "ras-mce-handler.h"
index 06777a28ee833dd25efb0c85b65388a21a3895fd..27e484b43f9e588996a6f1c6679c3a4c4ec72877 100644 (file)
 #include <stdint.h>
 #include <stdbool.h>
 #include "config.h"
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
-
-#define BIT(nr)                 (1UL << (nr))
-#define BIT_ULL(nr)             (1ULL << (nr))
+#include "types.h"
 
 extern long user_hz;
 
@@ -145,7 +141,6 @@ struct ras_cxl_poison_event {
        char overflow_ts[64];
 };
 
-#define SZ_512                          0x200
 #define CXL_HEADERLOG_SIZE              SZ_512
 #define CXL_HEADERLOG_SIZE_U32          (SZ_512 / sizeof(uint32_t))
 #define CXL_EVENT_RECORD_DATA_LENGTH   0x50
index 1cddc92dc68ed174739bc0f13d3b4cac001a1cc1..0c6644697820f88443dea7b1fa00ad469694b6bb 100644 (file)
@@ -14,8 +14,9 @@
 #ifndef __RAS_REPORT_H
 #define __RAS_REPORT_H
 
-#include "ras-record.h"
+#include "types.h"
 #include "ras-events.h"
+#include "ras-record.h"
 #include "ras-mc-handler.h"
 #include "ras-mce-handler.h"
 #include "ras-aer-handler.h"
index 447ac0bd0320f99fc17ed53af1ef10c370d46774..6f3a2723ff6196ace6bd79ac5b8d76ebafab3e54 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
-#include "ras-record.h"
+#include "types.h"
 #include "ras-logger.h"
 #include "ras-events.h"
+#include "ras-record.h"
 
 /*
  * Arguments(argp) handling logic and main
index bf861e56eeac1cd457b43a59ff2baf580ae6d17d..398d3185bd05432b10257e786325b6185c1943fd 100644 (file)
--- a/rbtree.h
+++ b/rbtree.h
 
 #include <stddef.h>
 
-#define container_of(ptr, type, member) ({                     \
-       const typeof(((type *)0)->member) *__mptr = (ptr);      \
-       (type *)((char *)__mptr - offsetof(type, member));      \
-})
-
 struct rb_node {
        unsigned long  rb_parent_color;
 #define        RB_RED          0
diff --git a/types.h b/types.h
new file mode 100644 (file)
index 0000000..1cf7556
--- /dev/null
+++ b/types.h
@@ -0,0 +1,139 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2013 Mauro Carvalho Chehab <mchehab+redhat@kernel.org>
+ * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __TYPES_H
+#define __TYPES_H
+
+#include <asm/bitsperlong.h>
+#include <assert.h>
+#include <linux/bits.h>
+#include <stdint.h>
+
+#define STR(x) #x
+
+/* Please keep the macros as much as possible alined with Linux Kernel ones */
+
+/*
+ * Force a compilation error if condition is true, but also produce a
+ * result (of value 0 and type int), so the expression can be used
+ * e.g. in a structure initializer (or where-ever else comma expressions
+ * aren't permitted).
+ */
+#define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
+
+/* Are two types/vars the same type (ignoring qualifiers)? */
+#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
+
+/* &a[0] degrades to a pointer: a different type from an array */
+#define __must_be_array(a)     BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
+
+/*
+ * This returns a constant expression while determining if an argument is
+ * a constant expression, most importantly without evaluating the argument.
+ * Glory to Martin Uecker <Martin.Uecker@med.uni-goettingen.de>
+ *
+ * Details:
+ * - sizeof() return an integer constant expression, and does not evaluate
+ *   the value of its operand; it only examines the type of its operand.
+ * - The results of comparing two integer constant expressions is also
+ *   an integer constant expression.
+ * - The first literal "8" isn't important. It could be any literal value.
+ * - The second literal "8" is to avoid warnings about unaligned pointers;
+ *   this could otherwise just be "1".
+ * - (long)(x) is used to avoid warnings about 64-bit types on 32-bit
+ *   architectures.
+ * - The C Standard defines "null pointer constant", "(void *)0", as
+ *   distinct from other void pointers.
+ * - If (x) is an integer constant expression, then the "* 0l" resolves
+ *   it into an integer constant expression of value 0. Since it is cast to
+ *   "void *", this makes the second operand a null pointer constant.
+ * - If (x) is not an integer constant expression, then the second operand
+ *   resolves to a void pointer (but not a null pointer constant: the value
+ *   is not an integer constant 0).
+ * - The conditional operator's third operand, "(int *)8", is an object
+ *   pointer (to type "int").
+ * - The behavior (including the return type) of the conditional operator
+ *   ("operand1 ? operand2 : operand3") depends on the kind of expressions
+ *   given for the second and third operands. This is the central mechanism
+ *   of the macro:
+ *   - When one operand is a null pointer constant (i.e. when x is an integer
+ *     constant expression) and the other is an object pointer (i.e. our
+ *     third operand), the conditional operator returns the type of the
+ *     object pointer operand (i.e. "int *"). Here, within the sizeof(), we
+ *     would then get:
+ *       sizeof(*((int *)(...))  == sizeof(int)  == 4
+ *   - When one operand is a void pointer (i.e. when x is not an integer
+ *     constant expression) and the other is an object pointer (i.e. our
+ *     third operand), the conditional operator returns a "void *" type.
+ *     Here, within the sizeof(), we would then get:
+ *       sizeof(*((void *)(...)) == sizeof(void) == 1
+ * - The equality comparison to "sizeof(int)" therefore depends on (x):
+ *     sizeof(int) == sizeof(int)     (x) was a constant expression
+ *     sizeof(int) != sizeof(void)    (x) was not a constant expression
+ */
+#define __is_constexpr(x) \
+       (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
+
+/**
+ * ARRAY_SIZE - get the number of elements in array @arr
+ * @arr: array to be sized
+ */
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+
+/* BIT handling */
+
+#define _AC(X,Y)       (X##Y)
+
+#define _UL(x)          (_AC(x, UL))
+#define _ULL(x)         (_AC(x, ULL))
+
+#define GENMASK_INPUT_CHECK(h, l) \
+       (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
+               __is_constexpr((l) > (h)), (l) > (h), 0)))
+
+#define GENMASK(h, l) \
+       (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
+#define GENMASK_ULL(h, l) \
+       (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
+
+#define BIT(nr)                 (_UL(1) << (nr))
+#define BIT_ULL(nr)             (_ULL(1) << (nr))
+
+/* Useful constants */
+
+#define MAX_PATH                       1024
+#define SZ_512                         0x200
+
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr:       the pointer to the member.
+ * @type:      the type of the container struct this is embedded in.
+ * @member:    the name of the member within the struct.
+ *
+ * WARNING: any const qualifier of @ptr is lost.
+ */
+#define container_of(ptr, type, member) ({                             \
+       void *__mptr = (void *)(ptr);                                   \
+       static_assert(__same_type(*(ptr), ((type *)0)->member) ||       \
+                     __same_type(*(ptr), void),                        \
+                     "pointer type mismatch in container_of()");       \
+       ((type *)(__mptr - offsetof(type, member))); })
+
+#endif