Skip to contentSkip to conversation

misc: mchp_pci1xxxx: mchp_pci1xxxx_gp: add unwind goto

PATCH In review Xinyi Hou 3 participants 3 messages Apr 9, 2023 – Apr 20, 2023

Subsystems (3)
lore
Share & tools
lore

Xinyi Hou

author
#0 lore raw

PATCH 1/1 misc: mchp_pci1xxxx: mchp_pci1xxxx_gp: add unwind goto

Smatch reported:

drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c:73 gp_aux_bus_probe() warn:
missing unwind goto?

In gp_aux_bus_probe(), when the allocation of aux_bus->aux_device_wrapper[1] fails, it needs to clean up the allocated resources.

Fix this by revising the return statement to a goto statement.

Fixes 393fc2f5948f ("misc: microchip: pci1xxxx: load auxiliary bus driver for the PIO function in the multi-function endpoint of pci1xxxx device.")

---
The issue is found by static analysis, and the patch remains untest.
---

 drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c +4 -2
index 32af2b14ff34..2c64b6b3cd9c 100644
@@ -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)
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines

-----Original Message-----
From: Xinyi Hou <[email protected]>
Sent: Sunday, April 9, 2023 6:18 PM
To: Kumaravel Thiagarajan - I21417 <[email protected]>; Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>

Smatch reported:

drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c:73 gp_aux_bus_probe() warn:
missing unwind goto?

In gp_aux_bus_probe(), when the allocation of aux_bus-

Quoted 8 lines
Quoted 1 line

aux_device_wrapper[1] fails, it needs to clean up the allocated resources.

Fix this by revising the return statement to a goto statement.

Fixes 393fc2f5948f ("misc: microchip: pci1xxxx: load auxiliary bus driver for

the PIO function in the multi-function endpoint of pci1xxxx device.")

Quoted 29 lines

---
The issue is found by static analysis, and the patch remains untest.
---

 drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c +0 -0
index 32af2b14ff34..2c64b6b3cd9c 100644
@@ -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-
Quoted 1 line

aux_device_wrapper[1]),

                                                 GFP_KERNEL);
drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c +4 -3
-       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.25.1

maintainer
#2 lore raw
Quoted 16 lines · On Thu, Apr 13, 2023 at 04:43:10AM +0000, [email protected]…
Quoted 16 lines

-----Original Message-----
From: Xinyi Hou <[email protected]>
Sent: Sunday, April 9, 2023 6:18 PM
To: Kumaravel Thiagarajan - I21417 <[email protected]>; Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>

Smatch reported:

drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c:73 gp_aux_bus_probe() warn:
missing unwind goto?

In gp_aux_bus_probe(), when the allocation of aux_bus-

Quoted 1 line

aux_device_wrapper[1] fails, it needs to clean up the allocated resources.

Quoted 9 lines
Quoted 6 lines

Fix this by revising the return statement to a goto statement.

Fixes 393fc2f5948f ("misc: microchip: pci1xxxx: load auxiliary bus driver for

the PIO function in the multi-function endpoint of pci1xxxx device.")

Quoted 2 lines

---
The issue is found by static analysis, and the patch remains untest.

Despite all the reviewers, this patch is incorrect :(

Please test patches, or better yet, restructure the code to not need to bail out in such a "deep" call path so that errors like this are not an issue.

thanks,

greg k-h