Linux driver-core infrastructure
 help / color / mirror / Atom feed
From: tarunsahu@google.com
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: dmatlack@google.com, Nicholas Piggin <npiggin@gmail.com>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	sourabhjain@linux.ibm.com,
	 "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	 Russell King <linux@armlinux.org.uk>,
	radheys@amd.com, skhawaja@google.com,  djeffery@redhat.com,
	Geoff Levand <geoff@infradead.org>,
	 Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	 linux-arm-kernel@lists.infradead.org, souravsgl@google.com,
	 linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	 driver-core@lists.linux.dev
Subject: Re: [PATCH v3 2/3] firmware/edd: use kobject_put() on edd_device_register() failure
Date: Thu, 20 Aug 2026 10:52:46 +0000	[thread overview]
Message-ID: <9huzik55kqrl.fsf@tarunix.c.googlers.com> (raw)
In-Reply-To: <20260814220652.GA101268@bhelgaas>

Hi,

Bjorn Helgaas <helgaas@kernel.org> 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@google.com>
>> Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
>> ---
>>  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
>> 

  reply	other threads:[~2026-08-20 10:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 21:00 [PATCH v3 0/3] Convert manual kfree(dev) to put_device() Tarun Sahu
2026-08-14 21:00 ` [PATCH v3 1/3] ARM: locomo: use put_device() on device_register() failure Tarun Sahu
2026-08-14 21:00 ` [PATCH v3 2/3] firmware/edd: use kobject_put() on edd_device_register() failure Tarun Sahu
2026-08-14 22:06   ` Bjorn Helgaas
2026-08-20 10:52     ` tarunsahu [this message]
2026-08-14 21:00 ` [PATCH v3 3/3] powerpc/ps3: use put_device() on device_register() failure in ps3_system_bus_device_register Tarun Sahu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9huzik55kqrl.fsf@tarunix.c.googlers.com \
    --to=tarunsahu@google.com \
    --cc=chleroy@kernel.org \
    --cc=djeffery@redhat.com \
    --cc=dmatlack@google.com \
    --cc=driver-core@lists.linux.dev \
    --cc=geoff@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=helgaas@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=radheys@amd.com \
    --cc=skhawaja@google.com \
    --cc=sourabhjain@linux.ibm.com \
    --cc=souravsgl@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox