Re: [PATCH v3 2/3] firmware/edd: use kobject_put() on edd_device_register() failure

From: tarunsahu

Date: Thu Aug 20 2026 - 06:57:51 EST


Hi,

Bjorn Helgaas <helgaas@xxxxxxxxxx> writes:

> On Fri, Aug 14, 2026 at 09:00:56PM +0000, Tarun Sahu wrote:
>> As per koject_init_and_add() function kernel document, even if this
>> function returns error kobject_put must be used instead of kfree.
>
> Thanks for adding this specific pointer. I wouldn't repost just for
> these nits, and wait at least a few days before reposting for any
> reason. But if you do repost:
>
> s/koject_init_and_add/kobject_init_and_add/
>
> Might also add "()" after function names consistently (kobject_put and
> kfree above, edd_release below). Also applies to the other patches.
>
> The current subject lines basically restate the C code; you might
> consider more of a focus on the problem. I ran this through gemini
> and I think it did a decent job:
>
> firmware: edd: Fix kobject reference leak on registration failure
>
> Per kobject_init_and_add() kernel-doc, calling kfree() directly on
> error bypasses reference counting and skips the kobject's release
> callback, leaking the reference.
>
> Use kobject_put() instead of kfree() on registration failure to fix
> this.

Thanks Bjron for reviewing. I will take care of them.

~Tarun
>
>> When edd_device_register() fails after initializing the kobject with
>> kobject_init_and_add(), calling kfree(edev) directly bypasses the
>> kobject release callback (edd_release) and leaks the allocated kobject
>> resources.
>>
>> Fix this by replacing direct kfree(edev) with kobject_put(&edev->kobj) on
>> registration failure.
>>
>> Signed-off-by: Tarun Sahu <tarunsahu@xxxxxxxxxx>
>> Reviewed-by: Sourabh Jain <sourabhjain@xxxxxxxxxxxxx>
>> ---
>> drivers/firmware/edd.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
>> index f980c5b56858..763e7b16d517 100644
>> --- a/drivers/firmware/edd.c
>> +++ b/drivers/firmware/edd.c
>> @@ -748,7 +748,7 @@ edd_init(void)
>>
>> rc = edd_device_register(edev, i);
>> if (rc) {
>> - kfree(edev);
>> + kobject_put(&edev->kobj);
>> goto out;
>> }
>> edd_devices[i] = edev;
>> --
>> 2.55.0.691.gc56d675ccc-goog
>>