代码拉取完成,页面将自动刷新
From 14af883bef2230df1411de3191044fbe12da66c5 Mon Sep 17 00:00:00 2001
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Date: Thu, 18 Jul 2024 10:43:17 +0200
Subject: [PATCH 56/85] rasdaemon: move type macros to a separate header
(types.h)
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>
---
non-standard-ampere.c | 2 +-
non-standard-hisi_hip08.c | 2 +-
non-standard-hisilicon.c | 2 +-
non-standard-yitian.c | 2 +-
ras-aer-handler.c | 2 +-
ras-arm-handler.c | 2 +-
ras-devlink-handler.c | 2 +-
ras-diskerror-handler.c | 2 +-
ras-events.c | 1 +
ras-events.h | 6 +-
ras-extlog-handler.c | 2 +-
ras-logger.h | 2 +-
ras-mc-handler.c | 2 +-
ras-mce-handler.c | 2 +-
ras-memory-failure-handler.c | 4 +-
ras-non-standard-handler.c | 2 +-
ras-non-standard-handler.h | 1 +
ras-page-isolation.h | 2 +-
ras-record.c | 1 +
ras-record.h | 65 +---------------
ras-report.h | 3 +-
rasdaemon.c | 3 +-
rbtree.h | 5 --
types.h | 139 +++++++++++++++++++++++++++++++++++
24 files changed, 166 insertions(+), 90 deletions(-)
create mode 100644 types.h
diff --git a/non-standard-ampere.c b/non-standard-ampere.c
index 0005b48..86148d6 100644
--- a/non-standard-ampere.c
+++ b/non-standard-ampere.c
@@ -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"
diff --git a/non-standard-hisi_hip08.c b/non-standard-hisi_hip08.c
index d90c6bf..4776832 100644
--- a/non-standard-hisi_hip08.c
+++ b/non-standard-hisi_hip08.c
@@ -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"
diff --git a/non-standard-hisilicon.c b/non-standard-hisilicon.c
index 00388ec..3d9fc30 100644
--- a/non-standard-hisilicon.c
+++ b/non-standard-hisilicon.c
@@ -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"
diff --git a/non-standard-yitian.c b/non-standard-yitian.c
index daadb95..d3dae38 100644
--- a/non-standard-yitian.c
+++ b/non-standard-yitian.c
@@ -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"
diff --git a/ras-aer-handler.c b/ras-aer-handler.c
index b6a6f1e..5a07559 100644
--- a/ras-aer-handler.c
+++ b/ras-aer-handler.c
@@ -21,7 +21,7 @@
#include <unistd.h>
#include "libtrace/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"
diff --git a/ras-arm-handler.c b/ras-arm-handler.c
index 55162a6..19150cb 100644
--- a/ras-arm-handler.c
+++ b/ras-arm-handler.c
@@ -17,7 +17,7 @@
#include <unistd.h>
#include "libtrace/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"
diff --git a/ras-devlink-handler.c b/ras-devlink-handler.c
index 4b22a8b..c1cacb7 100644
--- a/ras-devlink-handler.c
+++ b/ras-devlink-handler.c
@@ -23,7 +23,7 @@
#include <unistd.h>
#include "libtrace/kbuffer.h"
#include "ras-devlink-handler.h"
-#include "ras-record.h"
+#include "types.h"
#include "ras-logger.h"
#include "ras-report.h"
diff --git a/ras-diskerror-handler.c b/ras-diskerror-handler.c
index 9225a81..5764ca5 100644
--- a/ras-diskerror-handler.c
+++ b/ras-diskerror-handler.c
@@ -27,7 +27,7 @@
#include <sys/sysmacros.h>
#include "libtrace/kbuffer.h"
#include "ras-diskerror-handler.h"
-#include "ras-record.h"
+#include "types.h"
#include "ras-logger.h"
#include "ras-report.h"
diff --git a/ras-events.c b/ras-events.c
index 57d2026..21f787d 100644
--- a/ras-events.c
+++ b/ras-events.c
@@ -44,6 +44,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"
diff --git a/ras-events.h b/ras-events.h
index 5d32a00..5c17ede 100644
--- a/ras-events.h
+++ b/ras-events.h
@@ -19,15 +19,13 @@
#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,
diff --git a/ras-extlog-handler.c b/ras-extlog-handler.c
index 9e5c3e7..4cb69a3 100644
--- a/ras-extlog-handler.c
+++ b/ras-extlog-handler.c
@@ -26,7 +26,7 @@
#include "libtrace/kbuffer.h"
#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)
diff --git a/ras-logger.h b/ras-logger.h
index dbf1cb0..6afe41f 100644
--- a/ras-logger.h
+++ b/ras-logger.h
@@ -20,7 +20,7 @@
#include <syslog.h>
-#include "ras-record.h"
+#include "types.h"
/*
* Logging macros
diff --git a/ras-mc-handler.c b/ras-mc-handler.c
index c31468b..c438771 100644
--- a/ras-mc-handler.c
+++ b/ras-mc-handler.c
@@ -26,7 +26,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"
diff --git a/ras-mce-handler.c b/ras-mce-handler.c
index 524f40a..6e47814 100644
--- a/ras-mce-handler.c
+++ b/ras-mce-handler.c
@@ -25,7 +25,7 @@
#include <stdint.h>
#include "libtrace/kbuffer.h"
#include "ras-mce-handler.h"
-#include "ras-record.h"
+#include "types.h"
#include "ras-logger.h"
#include "ras-report.h"
diff --git a/ras-memory-failure-handler.c b/ras-memory-failure-handler.c
index 855c08c..04357f1 100644
--- a/ras-memory-failure-handler.c
+++ b/ras-memory-failure-handler.c
@@ -17,8 +17,10 @@
#include <stdlib.h>
#include <string.h>
#include "libtrace/kbuffer.h"
-#include "ras-record.h"
#include "ras-logger.h"
+
+#include "ras-memory-failure-handler.h"
+#include "types.h"
#include "ras-report.h"
#include "trigger.h"
diff --git a/ras-non-standard-handler.c b/ras-non-standard-handler.c
index c62a91b..c178857 100644
--- a/ras-non-standard-handler.c
+++ b/ras-non-standard-handler.c
@@ -18,7 +18,7 @@
#include <unistd.h>
#include "libtrace/kbuffer.h"
#include "ras-non-standard-handler.h"
-#include "ras-record.h"
+#include "types.h"
#include "ras-logger.h"
#include "ras-report.h"
diff --git a/ras-non-standard-handler.h b/ras-non-standard-handler.h
index 735ea76..9f22a62 100644
--- a/ras-non-standard-handler.h
+++ b/ras-non-standard-handler.h
@@ -15,6 +15,7 @@
#define __RAS_NON_STANDARD_HANDLER_H
#include "ras-events.h"
+#include "ras-record.h"
#include "libtrace/event-parse.h"
struct ras_ns_ev_decoder {
diff --git a/ras-page-isolation.h b/ras-page-isolation.h
index 7ccfca1..7da68c0 100644
--- a/ras-page-isolation.h
+++ b/ras-page-isolation.h
@@ -18,7 +18,7 @@
#include <stdbool.h>
#include <time.h>
-#include "ras-record.h"
+#include "types.h"
#include "rbtree.h"
#define PAGE_SHIFT 12
diff --git a/ras-record.c b/ras-record.c
index b0c9754..cf74d29 100644
--- a/ras-record.c
+++ b/ras-record.c
@@ -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"
diff --git a/ras-record.h b/ras-record.h
index a012ac6..f1edcc0 100644
--- a/ras-record.h
+++ b/ras-record.h
@@ -23,11 +23,7 @@
#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;
@@ -195,7 +191,6 @@ int ras_store_devlink_event(struct ras_events *ras, struct devlink_event *ev);
int ras_store_diskerror_event(struct ras_events *ras,
struct diskerror_event *ev);
int ras_store_mf_event(struct ras_events *ras, struct ras_mf_event *ev);
-<<<<<<< HEAD
#else
static inline int ras_mc_event_opendb(unsigned int cpu, struct ras_events *ras) { return 0; };
@@ -209,64 +204,6 @@ static inline int ras_store_arm_record(struct ras_events *ras, struct ras_arm_ev
static inline int ras_store_devlink_event(struct ras_events *ras, struct devlink_event *ev) { return 0; };
static inline int ras_store_diskerror_event(struct ras_events *ras, struct diskerror_event *ev) { return 0; };
static inline int ras_store_mf_event(struct ras_events *ras, struct ras_mf_event *ev) { return 0; };
-=======
-int ras_store_cxl_poison_event(struct ras_events *ras,
- struct ras_cxl_poison_event *ev);
-int ras_store_cxl_aer_ue_event(struct ras_events *ras,
- struct ras_cxl_aer_ue_event *ev);
-int ras_store_cxl_aer_ce_event(struct ras_events *ras,
- struct ras_cxl_aer_ce_event *ev);
-int ras_store_cxl_overflow_event(struct ras_events *ras,
- struct ras_cxl_overflow_event *ev);
-int ras_store_cxl_generic_event(struct ras_events *ras,
- struct ras_cxl_generic_event *ev);
-int ras_store_cxl_general_media_event(struct ras_events *ras,
- struct ras_cxl_general_media_event *ev);
-int ras_store_cxl_dram_event(struct ras_events *ras,
- struct ras_cxl_dram_event *ev);
-int ras_store_cxl_memory_module_event(struct ras_events *ras,
- struct ras_cxl_memory_module_event *ev);
-
-#else
-static inline int ras_mc_event_opendb(unsigned int cpu,
- struct ras_events *ras) { return 0; };
-static inline int ras_mc_event_closedb(unsigned int cpu,
- struct ras_events *ras) { return 0; };
-static inline int ras_store_mc_event(struct ras_events *ras,
- struct ras_mc_event *ev) { return 0; };
-static inline int ras_store_aer_event(struct ras_events *ras,
- struct ras_aer_event *ev) { return 0; };
-static inline int ras_store_mce_record(struct ras_events *ras,
- struct mce_event *ev) { return 0; };
-static inline int ras_store_extlog_mem_record(struct ras_events *ras,
- struct ras_extlog_event *ev) { return 0; };
-static inline int ras_store_non_standard_record(struct ras_events *ras,
- struct ras_non_standard_event *ev) { return 0; };
-static inline int ras_store_arm_record(struct ras_events *ras,
- struct ras_arm_event *ev) { return 0; };
-static inline int ras_store_devlink_event(struct ras_events *ras,
- struct devlink_event *ev) { return 0; };
-static inline int ras_store_diskerror_event(struct ras_events *ras,
- struct diskerror_event *ev) { return 0; };
-static inline int ras_store_mf_event(struct ras_events *ras,
- struct ras_mf_event *ev) { return 0; };
-static inline int ras_store_cxl_poison_event(struct ras_events *ras,
- struct ras_cxl_poison_event *ev) { return 0; };
-static inline int ras_store_cxl_aer_ue_event(struct ras_events *ras,
- struct ras_cxl_aer_ue_event *ev) { return 0; };
-static inline int ras_store_cxl_aer_ce_event(struct ras_events *ras,
- struct ras_cxl_aer_ce_event *ev) { return 0; };
-static inline int ras_store_cxl_overflow_event(struct ras_events *ras,
- struct ras_cxl_overflow_event *ev) { return 0; };
-static inline int ras_store_cxl_generic_event(struct ras_events *ras,
- struct ras_cxl_generic_event *ev) { return 0; };
-static inline int ras_store_cxl_general_media_event(struct ras_events *ras,
- struct ras_cxl_general_media_event *ev) { return 0; };
-static inline int ras_store_cxl_dram_event(struct ras_events *ras,
- struct ras_cxl_dram_event *ev) { return 0; };
-static inline int ras_store_cxl_memory_module_event(struct ras_events *ras,
- struct ras_cxl_memory_module_event *ev) { return 0; };
->>>>>>> 7a69b22 (rasdaemon: coding style cleanup)
#endif
diff --git a/ras-report.h b/ras-report.h
index dceedcc..a2edf3c 100644
--- a/ras-report.h
+++ b/ras-report.h
@@ -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"
diff --git a/rasdaemon.c b/rasdaemon.c
index 447ac0b..6f3a272 100644
--- a/rasdaemon.c
+++ b/rasdaemon.c
@@ -22,9 +22,10 @@
#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
diff --git a/rbtree.h b/rbtree.h
index 7fb15fa..2f79920 100644
--- a/rbtree.h
+++ b/rbtree.h
@@ -97,11 +97,6 @@
#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
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
--
2.33.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。