# Re: \[PATCH v2 2/3\] powerpc/kexec\_file: Fix null-ptr-def in extra size calculation

- From: Sourabh Jain \<sourabhjain@linux.ibm.com\>
- Date: 2026-07-29 04:01:52 
- List: linuxppc-dev
- Page: https://ratatoskr.run/linuxppc-dev/2026/07/17333033
- Thread: https://ratatoskr.run/linuxppc-dev/2026/07/17332584/t.md

```text


On 29/07/26 06:59, Jinjie Ruan wrote:
> A static Sashiko AI review identified a potential NULL pointer
> dereference in kexec_extra_fdt_size_ppc64().
>
> On platforms without any reserved memory regions,
> get_reserved_memory_ranges() can return 0 while leaving 'rmem'
> unallocated as NULL. Passing it directly leads to a kernel panic when
> evaluating 'rmem->nr_ranges'.

Yes that is possible, so it is worth adding NULL check for rmem.
Feel free to add:
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>

>
> Add a NULL check for 'rmem' to prevent this crash.
>
> Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
> Cc: Hari Bathini <hbathini@linux.ibm.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: <redacted>
> Fixes: 0d3ff067331e ("powerpc/kexec_file: fix extra size calculation for kexec FDT")
> Signed-off-by: Jinjie Ruan <redacted>
> ---
>   arch/powerpc/kexec/file_load_64.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
> index 8c72e12ea44e..6075b1c88511 100644
> --- a/arch/powerpc/kexec/file_load_64.c
> +++ b/arch/powerpc/kexec/file_load_64.c
> @@ -664,7 +664,7 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image, struct crash_mem *
>   		extra_size += (cpu_nodes - boot_cpu_node_count) * cpu_node_size();
>   
>   	/* Consider extra space for reserved memory ranges if any */
> -	if (rmem->nr_ranges > 0)
> +	if (rmem && rmem->nr_ranges > 0)
>   		extra_size += sizeof(struct fdt_reserve_entry) * rmem->nr_ranges;
>   
>   	return extra_size + kdump_extra_fdt_size_ppc64(image, cpu_nodes);


```
