RE: [PATCH] EDAC/sysfs: Fix error handling in edac_device_create_instance()

From: Zhuo, Qiuxu

Date: Thu Apr 30 2026 - 11:04:50 EST


Hi Guangshuo,

> From: Guangshuo Li <lgs201920130244@xxxxxxxxx>
> Sent: Thursday, April 30, 2026 8:00 PM
> To: Borislav Petkov <bp@xxxxxxxxx>; Luck, Tony <tony.luck@xxxxxxxxx>; Doug
> Thompson <dougthompson@xxxxxxxxxxxx>; Greg Kroah-Hartman
> <gregkh@xxxxxxx>; linux-edac@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
> Cc: Guangshuo Li <lgs201920130244@xxxxxxxxx>
> Subject: [PATCH] EDAC/sysfs: Fix error handling in
> edac_device_create_instance()
>
> Once kobject_init_and_add() failed, we should call kobject_put() to
> decrement the reference count of the initialized kobject. Or it could cause a
> reference count leak.
>
> The release callback of the instance kobject drops the reference of the main
> kobject, so replace kobject_put(main_kobj) with kobject_put(&instance-
> >kobj).
>
> As comment of kobject_init_and_add() says, if this function returns an error,
> kobject_put() must be called to properly clean up the memory associated
> with the object.
>
> This issue was found by a static analysis tool I am developing.
>

You may run:

grep -rn "kobject_init_and_add" drivers/edac/

and see there are several other places that need the same fix, like [1], [2] etc.

Could you please address all of them in your previous patch [3] instead of fixing only part of them?

[1] https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/edac/edac_device_sysfs.c#n519
[2] https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/edac/edac_pci_sysfs.c#n175
...
[3] https://lore.kernel.org/all/20260428160828.377129-1-lgs201920130244@xxxxxxxxx/

Thanks!
-Qiuxu