diff mbox

powerpc: Add missing error check to prom_find_boot_cpu()

Message ID 497a1d88a93.7082e0e9@auth.smtp.1and1.co.uk (mailing list archive)
State Accepted
Headers show

Commit Message

Darren Stevens Jan. 23, 2017, 7:42 p.m. UTC
prom_init.c calls 'instance-to-package' twice, but the return
is not checked during prom_find_boot_cpu(). The result is then
passed to prom_getprop, which could be PROM_ERROR.
Add a return check to prevent this.

This was found on a pasemi system, where CFE doesn't have a working
'instance-to package' prom call.
Before Commit 5c0484e25ec0 ('powerpc: Endian safe trampoline') the
area around addr 0 as mostly 0's and this doesn't cause a problem.
Once the macro 'FIXUP_ENDIAN' has been added to head_64.S, the low
memory area now has non-zero values, which cause the prom_getprop
call to hang.

Signed-off-by: Darren Stevens <darren@stevens-zone.net>

---

Comments

Michael Ellerman Jan. 27, 2017, 12:33 a.m. UTC | #1
On Mon, 2017-01-23 at 19:42:54 UTC, Darren Stevens wrote:
> prom_init.c calls 'instance-to-package' twice, but the return
> is not checked during prom_find_boot_cpu(). The result is then
> passed to prom_getprop, which could be PROM_ERROR.
> Add a return check to prevent this.
> 
> This was found on a pasemi system, where CFE doesn't have a working
> 'instance-to package' prom call.
> Before Commit 5c0484e25ec0 ('powerpc: Endian safe trampoline') the
> area around addr 0 as mostly 0's and this doesn't cause a problem.
> Once the macro 'FIXUP_ENDIAN' has been added to head_64.S, the low
> memory area now has non-zero values, which cause the prom_getprop
> call to hang.
> 
> Signed-off-by: Darren Stevens <darren@stevens-zone.net>

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/af2b7fa17eb92e52b65f96604448ff

cheers
Darren Stevens Jan. 27, 2017, 1:05 p.m. UTC | #2
Hello Michael

On 27/01/2017, Michael Ellerman wrote:
> On Mon, 2017-01-23 at 19:42:54 UTC, Darren Stevens wrote:
> Applied to powerpc fixes, thanks.
>
> https://git.kernel.org/powerpc/c/af2b7fa17eb92e52b65f96604448ff

Thanks, I was going to ask about backporting to 4.9 as it's a LTS now, but I
see from the above you've beaten me to it! Much appreciated.

I'm nearing the point where I will want to add the Nemo setup code to the
kernel, and I see 2 choices: 

Continue as we do, with #ifdefs in the setup.c / pci.c files.

Create 2 new files setup-nemo.c and pci-nemo.c - I am assuming this would be
the prefered option?

Regards
Darren
diff mbox

Patch

diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index ec47a93..ac83eb0 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -2834,6 +2834,9 @@  static void __init prom_find_boot_cpu(void)
 
 	cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu);
 
+	if (!PHANDLE_VALID(cpu_pkg))
+		return;
+
 	prom_getprop(cpu_pkg, "reg", &rval, sizeof(rval));
 	prom.cpu = be32_to_cpu(rval);