All of
 help / color / mirror / Atom feed
From: (Dave Martin)
Subject: [PATCH] ARM: Add safe diagnostic to indicate when __cpu_architecture isn't set up
Date: Tue, 16 Aug 2011 15:19:00 +0100	[thread overview]
Message-ID: <> (raw)

Although assing BUG() when __cpu_architecture is unexpectedly
CPU_ARCH_UNKNOWN seems like a good idea, in practice the kernel may
not be able to boot far enough even to write to the console in such
cases, even with earlyprintk enabled.

This patch adds a more useful diagnostic, and works out the cpu
architecture from scratch in such cases, instead of just returning
CPU_ARCH_UNKNOWN to the caller.

This patch is useful for debugging, but I'm not convinced it should
be merged.

Signed-off-by: Dave Martin <>
 arch/arm/include/asm/system.h |    9 +++++++--
 arch/arm/kernel/setup.c       |    2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
index b0445f7..d679d2f 100644
--- a/arch/arm/include/asm/system.h
+++ b/arch/arm/include/asm/system.h
@@ -110,8 +110,13 @@ extern int __cpu_architecture;
 static inline int __pure cpu_architecture(void)
-	BUG_ON(__cpu_architecture == CPU_ARCH_UNKNOWN);
-	return __cpu_architecture;
+	if (unlikely(__cpu_architecture == CPU_ARCH_UNKNOWN)) {
+		extern int __pure __get_cpu_architecture(void);
+		WARN_ONCE(1, "__cpu_architecture not set yet!\n");
+		return __get_cpu_architecture();
+	} else
+		return __cpu_architecture;
 extern void cpu_init(void);
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 1e0c1b3..188aae5 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -212,7 +212,7 @@ static const char *proc_arch[] = {
-static int __init __get_cpu_architecture(void)
+int __get_cpu_architecture(void)
 	int cpu_arch;

             reply	other threads:[~2011-08-16 14:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-16 14:19 Dave Martin [this message]
2011-08-16 14:45 ` [PATCH] ARM: Add safe diagnostic to indicate when __cpu_architecture isn't set up Tixy
2011-08-16 14:59   ` Nicolas Pitre
2011-08-16 16:15     ` Dave Martin
2011-08-16 16:22       ` Nicolas Pitre
2011-08-17 10:53         ` Dave Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.