Subject: [PATCH] pds_core: Fix possible double free in error handling path

From: hyper <[email-masked]>
Date: Fri, 1 Mar 2024 10:23:25 +0800

When auxiliary_device_add() returns error and then calls
auxiliary_device_uninit(), Callback function pdsc_auxbus_dev_release
calls kfree(padev) to free memory. We shouldn't call kfree(padev)
again in the error handling path.

Fix this by returning error directly after calling
auxiliary_device_uninit().

Fixes: 4569cce43bc6 ("pds_core: add auxiliary_bus devices")
Signed-off-by: hyper <[email-masked]>
---
 drivers/net/ethernet/amd/pds_core/auxbus.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/amd/pds_core/auxbus.c b/drivers/net/ethernet/amd/pds_core/auxbus.c
index 11c23a7f3172..d6eedd78d5cc 100644
--- a/drivers/net/ethernet/amd/pds_core/auxbus.c
+++ b/drivers/net/ethernet/amd/pds_core/auxbus.c
@@ -174,6 +174,8 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf,
 
 err_out_uninit:
 	auxiliary_device_uninit(aux_dev);
+	return ERR_PTR(err);
+
 err_out:
 	kfree(padev);
 	return ERR_PTR(err);
-- 
2.36.1