Skip to contentSkip to conversation

olpc: fix endian bug in openfirmware workaround

PATCH Applied Harvey Harrison 4 participants 8 messages Sep 23, 2008 – Feb 14, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 olpc: fix endian bug in openfirmware workaround

Boardrev is always treated as a u32 everywhere else, no reason to byteswap the 0xc2 value. The only use is to print out if it is a prerelease board, the test being:

(olpc_platform_info.boardrev & 0xf) < 8

Which is currently always true as be32_to_cpu(0xc2) & 0xf = 0 but I doubt that was the intention here. The consequences of the bug are pretty minor though (incorrect boardrev displayed in dmesg when ofw support not configured)

Also annotate the temporary used to read the boardrev in the ofw case.

The confusion was noticed by sparse:
arch/x86/kernel/olpc.c:206:32: warning: cast to restricted __be32

---
 arch/x86/kernel/olpc.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/olpc.c +3 -3
index 3e66722..7a13fac 100644
@@ -190,12 +190,12 @@ EXPORT_SYMBOL_GPL(olpc_ec_cmd);
 static void __init platform_detect(void)
 {
 	size_t propsize;
-	u32 rev;
+	__be32 rev;
 
 	if (ofw("getprop", 4, 1, NULL, "board-revision-int", &rev, 4,
 			&propsize) || propsize != 4) {
 		printk(KERN_ERR "ofw: getprop call failed!\n");
-		rev = 0;
+		rev = cpu_to_be32(0);
 	}
 	olpc_platform_info.boardrev = be32_to_cpu(rev);
 }
@@ -203,7 +203,7 @@ static void __init platform_detect(void)
 static void __init platform_detect(void)
 {
 	/* stopgap until OFW support is added to the kernel */
-	olpc_platform_info.boardrev = be32_to_cpu(0xc2);
+	olpc_platform_info.boardrev = 0xc2;
 }
 #endif
 
Signature · 1 line
1.6.0.2.471.g47a76
Applied
#1 lore raw
Quoted 11 lines · Harvey Harrison

Boardrev is always treated as a u32 everywhere else, no reason to byteswap the 0xc2 value. The only use is to print out if it is a prerelease board, the test being:

(olpc_platform_info.boardrev & 0xf) < 8

Which is currently always true as be32_to_cpu(0xc2) & 0xf = 0 but I doubt that was the intention here. The consequences of the bug are pretty minor though (incorrect boardrev displayed in dmesg when ofw support not configured)

Quoted 7 lines

Also annotate the temporary used to read the boardrev in the ofw case.

The confusion was noticed by sparse:
arch/x86/kernel/olpc.c:206:32: warning: cast to restricted __be32

applied to tip/x86/sparse-fixes, thanks Harvey!

Ingo

#2 lore raw

PATCH 1/1 olpc: fix model detection without OFW

In reply to Harvey Harrison

Harvey's endianness patch (e51a1ac2dfca9ad869471e88f828281db7e810c0) breaks model comparison on OLPC; the value 0xc2 needs to be scaled up by olpc_board(). The pre-patch version was wrong, but accidentally worked anyway (big-endian 0xc2 is big enough to satisfy all other board revisions, but little endian 0xc2 is not).

---
 arch/x86/kernel/olpc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/olpc.c +1 -1
index 7a13fac..4006c52 100644
@@ -203,7 +203,7 @@ static void __init platform_detect(void)
 static void __init platform_detect(void)
 {
 	/* stopgap until OFW support is added to the kernel */
-	olpc_platform_info.boardrev = 0xc2;
+	olpc_platform_info.boardrev = olpc_board(0xc2);
 }
 #endif
 
Signature · 1 line
1.6.1.3
Acked-by on v1 1/1
#3 lore raw

Re: [PATCH] olpc: fix model detection without OFW

As discussed on IRC, this has the Dilinger Seal Of Approval (tm).

Quoted 24 lines · On Fri, 13 Feb 2009 20:56:18 -0500 Chris Ball <[email protected]> wrote:

Harvey's endianness patch (e51a1ac2dfca9ad869471e88f828281db7e810c0) breaks model comparison on OLPC; the value 0xc2 needs to be scaled up by olpc_board(). The pre-patch version was wrong, but accidentally worked anyway (big-endian 0xc2 is big enough to satisfy all other board revisions, but little endian 0xc2 is not).

---
 arch/x86/kernel/olpc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/olpc.c +1 -1
index 7a13fac..4006c52 100644
@@ -203,7 +203,7 @@ static void __init platform_detect(void)
 static void __init platform_detect(void)
 {
 	/* stopgap until OFW support is added to the kernel */
-	olpc_platform_info.boardrev = 0xc2;
+	olpc_platform_info.boardrev = olpc_board(0xc2);
 }
 #endif
 
Acked-by Andres Salomon Applied
#4 lore raw

Re: [PATCH] olpc: fix model detection without OFW

Quoted 15 lines · Andres Salomon

As discussed on IRC, this has the Dilinger Seal Of Approval (tm).

Quoted 8 lines · On Fri, 13 Feb 2009 20:56:18 -0500 Chris Ball <[email protected]> wrote:

Harvey's endianness patch (e51a1ac2dfca9ad869471e88f828281db7e810c0)

breaks model comparison on OLPC; the value 0xc2 needs to be scaled up by olpc_board(). The pre-patch version was wrong, but accidentally worked anyway (big-endian 0xc2 is big enough to satisfy all other board revisions, but little endian 0xc2 is not).

Applied to tip:x86/urgent [for v2.6.29], thanks guys!

Did i get the impact-line below right?

Ingo

---------------->

Quoted 1 line

From 307250cda516547c0b0fe70dc3a3626bd82820cc Mon Sep 17 00:00:00 2001

From: Chris Ball <[email protected]>
Date: Fri, 13 Feb 2009 20:56:18 -0500
Subject: [PATCH] x86, olpc: fix model detection without OFW

Impact: make certain OLPC-board revision based quirks [mouse, sound] work properly

Harvey's endianness patch (e51a1ac2dfca9ad869471e88f828281db7e810c0) breaks model comparison on OLPC; the value 0xc2 needs to be scaled up by olpc_board(). The pre-patch version was wrong, but accidentally worked anyway (big-endian 0xc2 is big enough to satisfy all other board revisions, but little endian 0xc2 is not).

---
 arch/x86/kernel/olpc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/olpc.c +1 -1
index 7a13fac..4006c52 100644
@@ -203,7 +203,7 @@ static void __init platform_detect(void)
 static void __init platform_detect(void)
 {
 	/* stopgap until OFW support is added to the kernel */
-	olpc_platform_info.boardrev = 0xc2;
+	olpc_platform_info.boardrev = olpc_board(0xc2);
 }
 #endif
 
#5 lore raw

Re: [PATCH] olpc: fix model detection without OFW

On Sat, 14 Feb 2009 22:43:12 +0100
Ingo Molnar <[email protected]> wrote:
[...]

Quoted 7 lines

Applied to tip:x86/urgent [for v2.6.29], thanks guys!

Did i get the impact-line below right?

Ingo

More like -

Impact: garbled display, laptop is unusable

;)

The DCON detection code determines whether there's a DCON attached based upon the model (any XO model >= B2 is assumed to have a DCON). The LXFB driver determines which mode to use based upon whether or not it thinks there's a DCON attached, and the DCON/LXFB can't deal w/ standard modes.

So, the result is that LXFB attempts to use some random standard mode rather than the DCON-required 1200x900, and the display is unusable.

Quoted 37 lines

---------------->
From 307250cda516547c0b0fe70dc3a3626bd82820cc Mon Sep 17 00:00:00 2001
From: Chris Ball <[email protected]>
Date: Fri, 13 Feb 2009 20:56:18 -0500
Subject: [PATCH] x86, olpc: fix model detection without OFW

Impact: make certain OLPC-board revision based quirks [mouse, sound] work properly

Harvey's endianness patch (e51a1ac2dfca9ad869471e88f828281db7e810c0) breaks model comparison on OLPC; the value 0xc2 needs to be scaled up by olpc_board(). The pre-patch version was wrong, but accidentally worked anyway (big-endian 0xc2 is big enough to satisfy all other board revisions, but little endian 0xc2 is not).

---
 arch/x86/kernel/olpc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/olpc.c +1 -1
index 7a13fac..4006c52 100644
@@ -203,7 +203,7 @@ static void __init platform_detect(void)
 static void __init platform_detect(void)
 {
 	/* stopgap until OFW support is added to the kernel */
-	olpc_platform_info.boardrev = 0xc2;
+	olpc_platform_info.boardrev = olpc_board(0xc2);
 }
 #endif
 
#6 lore raw

Re: [PATCH] olpc: fix model detection without OFW

Quoted 8 lines · Andres Salomon

On Sat, 14 Feb 2009 22:43:12 +0100
Ingo Molnar <[email protected]> wrote:
[...]

Quoted 5 lines

Applied to tip:x86/urgent [for v2.6.29], thanks guys!

Did i get the impact-line below right?

Quoted 8 lines
Quoted 2 lines

Ingo

More like -

Impact: garbled display, laptop is unusable

;)

ah, okay :-) Serious regression that warrants urgent upstream routing.

Quoted 8 lines

The DCON detection code determines whether there's a DCON attached based upon the model (any XO model >= B2 is assumed to have a DCON). The LXFB driver determines which mode to use based upon whether or not it thinks there's a DCON attached, and the DCON/LXFB can't deal w/ standard modes.

So, the result is that LXFB attempts to use some random standard mode rather than the DCON-required 1200x900, and the display is unusable.

Where did my git grepping skills go wrong?

I git-grepped the code and this is the scope i found:

olpc_platform_info.boardrev is used for:

- a printk
- olpc_board_at_least() which is used in:
- drivers/input/mouse/hgpk.c: mouse driver quirk
- sound/pci/cs5535audio/cs5535audio_olpc.c: audio quirk

aha. I missed this roundabout impact:

- arch/x86/kernel/olpc.c: OLPC_F_DCON flag
- which is used in olpc_has_dcon(), which is used in:
- drivers/video/geode/gxfb_core.c: GX modes db
[ouch if this goes wrong!]
- drivers/video/geode/lxfb_core.c: ditto

So i guess the mouse and audio quirk point was correct too, but the major impact is the graphics mode array mismatch and the resulting nonsensical mode setting, right?

Ingo

#7 lore raw

Re: [PATCH] olpc: fix model detection without OFW

On Sat, 14 Feb 2009 23:14:29 +0100
Ingo Molnar <[email protected]> wrote:
[...]

Quoted 20 lines

Where did my git grepping skills go wrong?

I git-grepped the code and this is the scope i found:

olpc_platform_info.boardrev is used for:

- a printk
- olpc_board_at_least() which is used in:
- drivers/input/mouse/hgpk.c: mouse driver quirk
- sound/pci/cs5535audio/cs5535audio_olpc.c: audio quirk

aha. I missed this roundabout impact:

- arch/x86/kernel/olpc.c: OLPC_F_DCON flag
- which is used in olpc_has_dcon(), which is used in:
- drivers/video/geode/gxfb_core.c: GX modes db
[ouch if this goes
wrong!]
- drivers/video/geode/lxfb_core.c: ditto

Quoted 5 lines

So i guess the mouse and audio quirk point was correct too, but the major impact is the graphics mode array mismatch and the resulting nonsensical mode setting, right?

Ingo

Yep.