public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Bugfix in the error handling of gp_aux_bus_probe()
@ 2024-05-23 12:14 Yongzhi Liu
  2024-05-23 12:14 ` Yongzhi Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yongzhi Liu @ 2024-05-23 12:14 UTC (permalink / raw)
  To: kumaravel.thiagarajan, vaibhaavram.tl, arnd, gregkh
  Cc: linux-gpio, linux-kernel, jitxie, huntazhang, Yongzhi Liu

The error handling of gp_aux_bus_probe() invloves issues
related to double free and memory leak.

Yongzhi Liu (2):
  misc: microchip: pci1xxxx: fix double free in the error handling of
    gp_aux_bus_probe()
  misc: microchip: pci1xxxx: Fix a memory leak in the error handling of
    gp_aux_bus_probe()

 drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

-- 
2.36.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 0/2] Bugfix in the error handling of gp_aux_bus_probe()
  2024-05-23 12:14 [PATCH 0/2] Bugfix in the error handling of gp_aux_bus_probe() Yongzhi Liu
@ 2024-05-23 12:14 ` Yongzhi Liu
  2024-05-23 12:14 ` [PATCH 1/2] misc: microchip: pci1xxxx: fix double free " Yongzhi Liu
  2024-05-23 12:14 ` [PATCH 2/2] misc: microchip: pci1xxxx: Fix a memory leak " Yongzhi Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Yongzhi Liu @ 2024-05-23 12:14 UTC (permalink / raw)
  To: kumaravel.thiagarajan, vaibhaavram.tl, arnd, gregkh
  Cc: linux-gpio, linux-kernel, jitxie, huntazhang, Yongzhi Liu

The error handling of gp_aux_bus_probe() invloves issues
related to double free and memory leak.

Yongzhi Liu (2):
  misc: microchip: pci1xxxx: fix double free in the error handling of
    gp_aux_bus_probe()
  misc: microchip: pci1xxxx: Fix a memory leak in the error handling of
    gp_aux_bus_probe()

 drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

-- 
2.36.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] misc: microchip: pci1xxxx: fix double free in the error handling of gp_aux_bus_probe()
  2024-05-23 12:14 [PATCH 0/2] Bugfix in the error handling of gp_aux_bus_probe() Yongzhi Liu
  2024-05-23 12:14 ` Yongzhi Liu
@ 2024-05-23 12:14 ` Yongzhi Liu
  2024-05-23 12:14 ` [PATCH 2/2] misc: microchip: pci1xxxx: Fix a memory leak " Yongzhi Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Yongzhi Liu @ 2024-05-23 12:14 UTC (permalink / raw)
  To: kumaravel.thiagarajan, vaibhaavram.tl, arnd, gregkh
  Cc: linux-gpio, linux-kernel, jitxie, huntazhang, Yongzhi Liu

When auxiliary_device_add() returns error and then calls
auxiliary_device_uninit(), callback function
gp_auxiliary_device_release() calls ida_free() and
kfree(aux_device_wrapper) to free memory. We should't
call them again in the error handling path.

Fix this by skipping the redundant cleanup functions.

Fixes: 393fc2f5948f ("misc: microchip: pci1xxxx: load auxiliary bus driver for the PIO function in the multi-function endpoint of pci1xxxx device.")
Signed-off-by: Yongzhi Liu <hyperlyzcs@gmail.com>
---
 drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c
index 32af2b14ff34..de75d89ef53e 100644
--- a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c
+++ b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c
@@ -111,6 +111,7 @@ static int gp_aux_bus_probe(struct pci_dev *pdev, const struct pci_device_id *id
 
 err_aux_dev_add_1:
 	auxiliary_device_uninit(&aux_bus->aux_device_wrapper[1]->aux_dev);
+	goto err_aux_dev_add_0;
 
 err_aux_dev_init_1:
 	ida_free(&gp_client_ida, aux_bus->aux_device_wrapper[1]->aux_dev.id);
@@ -120,6 +121,7 @@ static int gp_aux_bus_probe(struct pci_dev *pdev, const struct pci_device_id *id
 
 err_aux_dev_add_0:
 	auxiliary_device_uninit(&aux_bus->aux_device_wrapper[0]->aux_dev);
+	goto err_ret;
 
 err_aux_dev_init_0:
 	ida_free(&gp_client_ida, aux_bus->aux_device_wrapper[0]->aux_dev.id);
@@ -127,6 +129,7 @@ static int gp_aux_bus_probe(struct pci_dev *pdev, const struct pci_device_id *id
 err_ida_alloc_0:
 	kfree(aux_bus->aux_device_wrapper[0]);
 
+err_ret:
 	return retval;
 }
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] misc: microchip: pci1xxxx: Fix a memory leak in the error handling of gp_aux_bus_probe()
  2024-05-23 12:14 [PATCH 0/2] Bugfix in the error handling of gp_aux_bus_probe() Yongzhi Liu
  2024-05-23 12:14 ` Yongzhi Liu
  2024-05-23 12:14 ` [PATCH 1/2] misc: microchip: pci1xxxx: fix double free " Yongzhi Liu
@ 2024-05-23 12:14 ` Yongzhi Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Yongzhi Liu @ 2024-05-23 12:14 UTC (permalink / raw)
  To: kumaravel.thiagarajan, vaibhaavram.tl, arnd, gregkh
  Cc: linux-gpio, linux-kernel, jitxie, huntazhang, Yongzhi Liu

There is a memory leak (forget to free allocated buffers) in a
memory allocation failure path.

Fix it to jump to the correct error handling code.

Fixes: 393fc2f5948f ("misc: microchip: pci1xxxx: load auxiliary bus driver for the PIO function in the multi-function endpoint of pci1xxxx device.")
Signed-off-by: Yongzhi Liu <hyperlyzcs@gmail.com>
---
 drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c
index de75d89ef53e..34c9be437432 100644
--- a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c
+++ b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c
@@ -69,8 +69,10 @@ static int gp_aux_bus_probe(struct pci_dev *pdev, const struct pci_device_id *id
 
 	aux_bus->aux_device_wrapper[1] = kzalloc(sizeof(*aux_bus->aux_device_wrapper[1]),
 						 GFP_KERNEL);
-	if (!aux_bus->aux_device_wrapper[1])
-		return -ENOMEM;
+	if (!aux_bus->aux_device_wrapper[1]) {
+		retval =  -ENOMEM;
+		goto err_aux_dev_add_0;
+	}
 
 	retval = ida_alloc(&gp_client_ida, GFP_KERNEL);
 	if (retval < 0)
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-23 12:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-23 12:14 [PATCH 0/2] Bugfix in the error handling of gp_aux_bus_probe() Yongzhi Liu
2024-05-23 12:14 ` Yongzhi Liu
2024-05-23 12:14 ` [PATCH 1/2] misc: microchip: pci1xxxx: fix double free " Yongzhi Liu
2024-05-23 12:14 ` [PATCH 2/2] misc: microchip: pci1xxxx: Fix a memory leak " Yongzhi Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox