Thread (4 messages) flat view 4 messages, 1 author, 8h ago
HOTtoday REVIEWED: 1 (0M)

1 review trailer.

[PATCH v4 1/3] ARM: locomo: Fix device reference leak on registration failure

From: Tarun Sahu <hidden>
Date: 2026-09-04 17:16:22
Also in: linux-arm-kernel, lkml
Subsystem: arm port, the rest · Maintainers: Russell King, Linus Torvalds

As per device_register() kernel-doc, calling kfree() directly on
error bypasses reference counting and skips the device release
callback, leaking the reference. Even in case of device_register()
failure, Calling the put_device is advised.

Fix this by calling put_device() on device_registration failure
instead of kfree().

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reviewed-by: Sourabh Jain <redacted>
Signed-off-by: Tarun Sahu <redacted>
---
 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.979.g7e5102b832-goog

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help