[PATCH v3 1/3] ARM: locomo: use put_device() on device_register() failure

Tarun Sahu tarunsahu at google.com
Fri Aug 14 14:00:55 PDT 2026


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 at google.com>
Reviewed-by: Sourabh Jain <sourabhjain at 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




More information about the linux-arm-kernel mailing list