All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tarun Sahu <tarunsahu@google.com>
To: helgaas@kernel.org, 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>
Cc: linux-arm-kernel@lists.infradead.org, souravsgl@google.com,
	 linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	 driver-core@lists.linux.dev, Tarun Sahu <tarunsahu@google.com>
Subject: [PATCH v3 1/3] ARM: locomo: use put_device() on device_register() failure
Date: Fri, 14 Aug 2026 21:00:55 +0000	[thread overview]
Message-ID: <20260814210057.4102768-2-tarunsahu@google.com> (raw)
In-Reply-To: <20260814210057.4102768-1-tarunsahu@google.com>

As per device_register() function kernel documentation says "even
when device_register return error always use put_device() instead
of kfree()"

Fix such instance in locomo driver by replacing direct kfree(dev)
with put_device(&dev->dev) when device_register() returns an error.

Signed-off-by: Tarun Sahu <tarunsahu@google.com>
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
 arch/arm/common/locomo.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/arm/common/locomo.c b/arch/arm/common/locomo.c
index 55e360452828..0f6689d343b0 100644
--- a/arch/arm/common/locomo.c
+++ b/arch/arm/common/locomo.c
@@ -223,10 +223,8 @@ locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
 	int ret;
 
 	dev = kzalloc_obj(struct locomo_dev);
-	if (!dev) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	if (!dev)
+		return -ENOMEM;
 
 	/*
 	 * If the parent device has a DMA mask associated with it,
@@ -255,10 +253,11 @@ locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
 
 	ret = device_register(&dev->dev);
 	if (ret) {
- out:
-		kfree(dev);
+		put_device(&dev->dev);
+		return ret;
 	}
-	return ret;
+
+	return 0;
 }
 
 #ifdef CONFIG_PM
-- 
2.55.0.691.gc56d675ccc-goog



  reply	other threads:[~2026-08-14 21:01 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 ` Tarun Sahu [this message]
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
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=20260814210057.4102768-2-tarunsahu@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.