powerpc/machdep: warn when machine_is() used too early
authorNathan Lynch <nathanl@linux.ibm.com>
Mon, 13 Feb 2023 19:23:51 +0000 (13:23 -0600)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 15 Feb 2023 11:41:11 +0000 (22:41 +1100)
machine_is() can't provide correct results before probe_machine() has
run. Warn when it's used too early in boot, placing the WARN_ON() in a
helper function so the reported file:line indicates exactly what went
wrong.

checkpatch complains about __attribute__((weak)) in the patch, so
change that to __weak, and align the line continuations as well.

Signed-off-by: Nathan Lynch <nathanl@linux.ibm.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230210-warn-on-machine-is-before-probe-machine-v2-1-b57f8243c51c@linux.ibm.com
arch/powerpc/include/asm/machdep.h

index 378b8d5836a7b8fe249a19fe43ffa8edeb673e92..459736d5e511745576f0d1402cc8c422764afc49 100644 (file)
@@ -3,6 +3,7 @@
 #define _ASM_POWERPC_MACHDEP_H
 #ifdef __KERNEL__
 
+#include <linux/compiler.h>
 #include <linux/seq_file.h>
 #include <linux/init.h>
 #include <linux/dma-mapping.h>
@@ -220,11 +221,16 @@ extern struct machdep_calls *machine_id;
        EXPORT_SYMBOL(mach_##name);                             \
        struct machdep_calls mach_##name __machine_desc =
 
-#define machine_is(name) \
-       ({ \
-               extern struct machdep_calls mach_##name \
-                       __attribute__((weak));           \
-               machine_id == &mach_##name; \
+static inline bool __machine_is(const struct machdep_calls *md)
+{
+       WARN_ON(!machine_id); // complain if used before probe_machine()
+       return machine_id == md;
+}
+
+#define machine_is(name)                                        \
+       ({                                                      \
+               extern struct machdep_calls mach_##name __weak; \
+               __machine_is(&mach_##name);                     \
        })
 
 static inline void log_error(char *buf, unsigned int err_type, int fatal)