Re: [PATCH v2] EDAC/versalnet: Fix resource leaks and NULL derefs in init_versalnet()
From: Borislav Petkov
Date: Thu Feb 26 2026 - 08:02:46 EST
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
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette