Re: [PATCH 5/5] EDAC/versalnet: Fix device name memory leak

From: Borislav Petkov

Date: Sun Mar 22 2026 - 12:15:34 EST


On Sun, Mar 22, 2026 at 06:11:49AM -0700, Prasanna Kumar T S M wrote:
> The device name allocated via kzalloc() in init_one_mc() is assigned to
> dev->init_name but never freed on the normal removal path.
> device_register() copies init_name and then sets dev->init_name to NULL,
> so the name pointer becomes unreachable from the device. Thus leaking
> memory.
>
> Track the name pointer in mc_priv and free it in remove_one_mc().

No, get rid of the name allocation and allocate a char name[MC_NAME_LEN] on the
stack in init_one_mc() which you pass into device_register(), it copies it and
we forget about it.

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette