Skip to content

Commit 6ba422c

Browse files
antonblanchardmpe
authored andcommitted
powerpc/64: Avoid panic during boot due to divide by zero in init_cache_info()
I see a panic in early boot when building with a recent gcc toolchain. The issue is a divide by zero, which is undefined. Older toolchains let us get away with it: int foo(int a) { return a / 0; } foo: li 9,0 divw 3,3,9 extsw 3,3 blr But newer ones catch it: foo: trap Add a check to avoid the divide by zero. Fixes: e2827fe ("powerpc/64: Clean up ppc64_caches using a struct per cache") Signed-off-by: Anton Blanchard <[email protected]> Acked-by: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 014d02c commit 6ba422c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/powerpc/kernel/setup_64.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ static void init_cache_info(struct ppc_cache_info *info, u32 size, u32 lsize,
408408
info->line_size = lsize;
409409
info->block_size = bsize;
410410
info->log_block_size = __ilog2(bsize);
411-
info->blocks_per_page = PAGE_SIZE / bsize;
411+
if (bsize)
412+
info->blocks_per_page = PAGE_SIZE / bsize;
413+
else
414+
info->blocks_per_page = 0;
412415

413416
if (sets == 0)
414417
info->assoc = 0xffff;

0 commit comments

Comments
 (0)