Thread (8 messages) flat view 8 messages, 2 authors, 23d ago

Re: [PATCH 3/4] EDAC/versalnet: use put_device() on device_register() failure

From: Pandey, Radhey Shyam <hidden>
Date: 2026-08-13 09:11:52
Also in: driver-core, linux-arm-kernel, linux-edac, lkml

On 8/11/2026 4:09 PM, tarunsahu@google.com wrote:
"Pandey, Radhey Shyam" [off-list ref] writes:
quoted
On 8/10/2026 9:58 PM, Tarun Sahu wrote:
quoted
When device_register() fails, calling kfree(dev) directly bypasses the
device_release() callback (versal_edac_release) and leaks the allocated
driver core structures.

Fix this by calling put_device(dev) when device_register() returns an
error, ensuring proper refcount decrement and release cleanup.

Signed-off-by: Tarun Sahu <redacted>
Thanks for the patch. FYI, this issue is already being addressed in an
ongoing series.
https://lore.kernel.org/all/20260724171945.2812749-5-shubhrajyoti.datta@amd.com/ (local)
That is good. Should it go as saperate patch or it fits very well with
the above series. I will drop it incase of later. WDYT?
Please drop it from your series as the fix done in Shubhrajyoti's
series is complete.

Thanks,
Radhey
~Tarun
quoted
-Radhey
quoted
---
   drivers/edac/versalnet_edac.c | 6 ++++--
   1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
index 97ec05d68bbb..2912b3658915 100644
--- a/drivers/edac/versalnet_edac.c
+++ b/drivers/edac/versalnet_edac.c
@@ -829,8 +829,10 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
   	dev->release = versal_edac_release;
   
   	rc = device_register(dev);
-	if (rc)
+	if (rc) {
+		put_device(dev);
   		goto err_mc_free;
+	}
   
   	mci->pdev = dev;
   	mc_init(mci, dev);
@@ -852,9 +854,9 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
   	device_unregister(mci->pdev);
   err_mc_free:
   	edac_mc_free(mci);
+	return rc;
   err_dev_free:
   	kfree(dev);
-
   	return rc;
   }
   
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help