[PATCH] powerpc: Avoid panic during boot due to divide by zero in init_cache_info()

Michael Ellerman mpe at ellerman.id.au
Sun Mar 5 21:36:43 AEDT 2017


Anton Blanchard <anton at ozlabs.org> writes:
> diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
> index adf2084..afd1c26 100644
> --- a/arch/powerpc/kernel/setup_64.c
> +++ b/arch/powerpc/kernel/setup_64.c
> @@ -408,7 +408,8 @@ static void init_cache_info(struct ppc_cache_info *info, u32 size, u32 lsize,
>  	info->line_size = lsize;
>  	info->block_size = bsize;
>  	info->log_block_size = __ilog2(bsize);
> -	info->blocks_per_page = PAGE_SIZE / bsize;
> +	if (bsize)
> +		info->blocks_per_page = PAGE_SIZE / bsize;
  
And we should probably initialise it to zero just in case, so I added:

diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index afd1c2623459..9cfaa8b69b5f 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -410,6 +410,8 @@ static void init_cache_info(struct ppc_cache_info *info, u32 size, u32 lsize,
 	info->log_block_size = __ilog2(bsize);
 	if (bsize)
 		info->blocks_per_page = PAGE_SIZE / bsize;
+	else
+		info->blocks_per_page = 0;
 
 	if (sets == 0)
 		info->assoc = 0xffff;

cheers


More information about the Linuxppc-dev mailing list