Skip to content

Commit 388defd

Browse files
nathanlynchmpe
authored andcommitted
powerpc/machdep: warn when machine_is() used too early
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 <[email protected]> Reviewed-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/20230210-warn-on-machine-is-before-probe-machine-v2-1-b57f8243c51c@linux.ibm.com
1 parent 77e82fa commit 388defd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

arch/powerpc/include/asm/machdep.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _ASM_POWERPC_MACHDEP_H
44
#ifdef __KERNEL__
55

6+
#include <linux/compiler.h>
67
#include <linux/seq_file.h>
78
#include <linux/init.h>
89
#include <linux/dma-mapping.h>
@@ -220,11 +221,16 @@ extern struct machdep_calls *machine_id;
220221
EXPORT_SYMBOL(mach_##name); \
221222
struct machdep_calls mach_##name __machine_desc =
222223

223-
#define machine_is(name) \
224-
({ \
225-
extern struct machdep_calls mach_##name \
226-
__attribute__((weak)); \
227-
machine_id == &mach_##name; \
224+
static inline bool __machine_is(const struct machdep_calls *md)
225+
{
226+
WARN_ON(!machine_id); // complain if used before probe_machine()
227+
return machine_id == md;
228+
}
229+
230+
#define machine_is(name) \
231+
({ \
232+
extern struct machdep_calls mach_##name __weak; \
233+
__machine_is(&mach_##name); \
228234
})
229235

230236
static inline void log_error(char *buf, unsigned int err_type, int fatal)

0 commit comments

Comments
 (0)