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

From: Borislav Petkov

Date: Mon Feb 23 2026 - 08:49:19 EST


On February 22, 2026 10:39:18 AM UTC, Eric-Terminal <ericterminal@xxxxxxxxx> 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().
>
> - 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>
>---
> drivers/edac/versalnet_edac.c | 29 ++++++++++++++++++++++++-----

So that particular area of stinking goo is being dealt with here:

<https://lore.kernel.org/all/20251104093932.3838876-1-shubhrajyoti.datta@xxxxxxx/T/#u>

And I'd usually say you can take the current diffs, productize them and send them after testing.

However, testing is the problem here - I highly doubt you have access to the hardware and Shubhrajyoti is probably one of small number of people who can test it.

Except that he's not really moving here - this particular issue has been outstanding for at least three months.

I'll ping him when I get back from vacation to see whether there's still interest in this driver or I can remove it for lack of support.

Oh well.

--
Small device. Typos and formatting crap