RE: [PATCH v2] EDAC/versalnet: Fix resource leaks and NULL derefs in init_versalnet()

From: Datta, Shubhrajyoti

Date: Thu Feb 26 2026 - 12:55:43 EST


[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Borislav Petkov <bp@xxxxxxxxx>
> Sent: Thursday, February 26, 2026 6:30 PM
> To: Eric-Terminal <ericterminal@xxxxxxxxx>
> Cc: Datta, Shubhrajyoti <shubhrajyoti.datta@xxxxxxx>; Tony Luck
> <tony.luck@xxxxxxxxx>; linux-edac@xxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH v2] EDAC/versalnet: Fix resource leaks and NULL derefs in
> init_versalnet()
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> On Thu, Feb 26, 2026 at 07:29:07PM +0800, Eric-Terminal wrote:
> > From: Yufan Chen <ericterminal@xxxxxxxxx>
> >
> > init_versalnet() has several bugs in its error handling. kzalloc() and
> > kmalloc() return values are used without NULL checks, causing a NULL
> > pointer dereference when allocation fails. The cleanup loop uses while
> > (i--) which skips the current failing index, leaking the resources
> > already allocated for that slot. edac_mc_del_mc() is called
> > unconditionally during unwind, even for controllers that were never
> > registered with edac_mc_add_mc(). Also, sprintf() is used instead of
> > snprintf() on a fixed-size buffer.
> >
> > Fix by adding NULL checks for dev and name allocations, replacing
> > while (i--) with for (j = i; j >= 0; j--) to include the failing
> > index, tracking successful edac_mc_add_mc() calls with a bool array,
> > and switching to snprintf().
> >
> > Signed-off-by: Yufan Chen <ericterminal@xxxxxxxxx>
> > Reviewed-by: Shubhrajyoti Datta <shubhrajyoti.datta@xxxxxxx>
> > ---
> > v2: Correct Signed-off-by name and add Reviewed-by tag. Fix commit message
> formatting.
> >
> > drivers/edac/versalnet_edac.c | 29 ++++++++++++++++++++++++-----
> > 1 file changed, 24 insertions(+), 5 deletions(-)
>
> No, thanks, we'll do the proper cleanup here:
>
> https://lore.kernel.org/all/20251104093932.3838876-1-
> shubhrajyoti.datta@xxxxxxx/T/#u

My apologies somehow I had missed it.
Tested it on the hardware.
>
> --
> Regards/Gruss,
> Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette