Re: [PATCH] dpaa2-switch: prevent ZERO_SIZE_PTR dereference when num_ifs is zero
From: Andrew Lunn
Date: Wed Jan 28 2026 - 08:51:06 EST
On Wed, Jan 28, 2026 at 04:07:34PM +0800, Junrui Luo wrote:
> The driver allocates arrays for ports, FDBs, and filter blocks using
> kcalloc() with ethsw->sw_attr.num_ifs as the element count. When the
> device reports zero interfaces (either due to hardware configuration
> or firmware issues), kcalloc(0, ...) returns ZERO_SIZE_PTR (0x10)
> instead of NULL.
>
> Later in dpaa2_switch_probe(), the NAPI initialization unconditionally
> accesses ethsw->ports[0]->netdev, which attempts to dereference
> ZERO_SIZE_PTR (address 0x10), resulting in a kernel panic.
>
> Add a check to ensure num_ifs is greater than zero after retrieving
> device attributes. This prevents the zero-sized allocations and
> subsequent invalid pointer dereference.
>
> Reported-by: Yuhao Jiang <danisjiang@xxxxxxxxx>
> Reported-by: Junrui Luo <moonafterrain@xxxxxxxxxxx>
> Fixes: 0b1b71370458 ("staging: dpaa2-switch: handle Rx path on control interface")
> Signed-off-by: Junrui Luo <moonafterrain@xxxxxxxxxxx>
The patch itself looks O.K. However, we ask that fixes are based on
net, and indicate this in the subject line.
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
Reviewed-by: Andrew Lunn <andrew@xxxxxxx>
Andrew