Re: [PATCH 2/9] EDAC/versalnet: Add NULL check for mci in remove_one_mc()
"Pandey, Radhey Shyam" <[email protected]> Mon, 27 Jul 2026 13:41:52 +0530
| Newsgroups | org.kernel.vger.linux-edac,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On 7/24/2026 10:49 PM, Shubhrajyoti Datta wrote:
> If a controller's configuration specifies an unrecognized bus width,
> init_one_mc() returns 0 but skips allocating priv->mci[ctl_num], leaving
> it NULL. On module unload or probe failure, remove_one_mc() is called for
> all controllers and unconditionally dereferences priv->mci[i], causing a
> kernel panic.
>
> Add a NULL pointer check for mci before dereferencing it.
>
> Unable to handle kernel NULL pointer dereference at virtual address 0000000000000390
> Internal error: Oops: 0000000096000004 [#1] SMP
> Hardware name: Xilinx Versal NET VNX (DT)
> pc : mc_remove+0x34/0x88
> lr : mc_remove+0x4c/0x88
> Call trace:
> mc_remove+0x34/0x88
> platform_remove+0x2c/0x70
> device_remove+0x48/0x7c
> device_release_driver_internal+0x1c8/0x224
> device_driver_detach+0x18/0x28
> unbind_store+0xb4/0xb8
>
> Fixes: 62a9fc50e8d9 ("EDAC/versalnet: Refactor memory controller initialization and cleanup")
Confirm on fixes tag. The bug likely goes back to the original driver.
> Cc: [email protected]
There is no CC to stable kernel in email.
Below changes looks fine to me. With above tag fixed.
Reviewed-by: Radhey Shyam Pandey <[email protected]>
Thanks!
> Signed-off-by: Shubhrajyoti Datta <[email protected]>
> ---
>
> drivers/edac/versalnet_edac.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
> index 316f8f79c4d8..05dc34504cc2 100644
> --- a/drivers/edac/versalnet_edac.c
> +++ b/drivers/edac/versalnet_edac.c
> @@ -769,6 +769,9 @@ static void remove_one_mc(struct mc_priv *priv, int i)
> struct mem_ctl_info *mci;
>
> mci = priv->mci[i];
> + if (!mci)
> + return;
> +
> device_unregister(mci->pdev);
> edac_mc_del_mc(mci->pdev);
> edac_mc_free(mci);