* [PATCH] misc: mchp_pci1xxxx: mchp_pci1xxxx_gp: add unwind goto
@ 2023-04-09 12:48 Xinyi Hou
2023-04-13 4:43 ` Kumaravel.Thiagarajan
0 siblings, 1 reply; 3+ messages in thread
From: Xinyi Hou @ 2023-04-09 12:48 UTC (permalink / raw)
To: Kumaravel Thiagarajan, Arnd Bergmann, Greg Kroah-Hartman
Cc: Xinyi Hou, Dongliang Mu, linux-gpio, linux-kernel
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.")
Signed-off-by: Xinyi Hou <Y_Ashley@163.com>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
---
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(-)
diff --git a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c
index 32af2b14ff34..2c64b6b3cd9c 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.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread* RE: [PATCH] misc: mchp_pci1xxxx: mchp_pci1xxxx_gp: add unwind goto
2023-04-09 12:48 [PATCH] misc: mchp_pci1xxxx: mchp_pci1xxxx_gp: add unwind goto Xinyi Hou
@ 2023-04-13 4:43 ` Kumaravel.Thiagarajan
2023-04-20 12:04 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Kumaravel.Thiagarajan @ 2023-04-13 4:43 UTC (permalink / raw)
To: Y_Ashley, arnd, gregkh; +Cc: dzm91, linux-gpio, linux-kernel
> -----Original Message-----
> From: Xinyi Hou <Y_Ashley@163.com>
> Sent: Sunday, April 9, 2023 6:18 PM
> To: Kumaravel Thiagarajan - I21417
> <Kumaravel.Thiagarajan@microchip.com>; Arnd Bergmann
> <arnd@arndb.de>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>
> 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.")
> Signed-off-by: Xinyi Hou <Y_Ashley@163.com>
> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
Reviewed-by: Kumaravel Thiagarajan <kumaravel.thiagarajan@microchip.com>
> ---
> 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(-)
>
> diff --git a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c
> b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c
> index 32af2b14ff34..2c64b6b3cd9c 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.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] misc: mchp_pci1xxxx: mchp_pci1xxxx_gp: add unwind goto
2023-04-13 4:43 ` Kumaravel.Thiagarajan
@ 2023-04-20 12:04 ` Greg KH
0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2023-04-20 12:04 UTC (permalink / raw)
To: Kumaravel.Thiagarajan; +Cc: Y_Ashley, arnd, dzm91, linux-gpio, linux-kernel
On Thu, Apr 13, 2023 at 04:43:10AM +0000, Kumaravel.Thiagarajan@microchip.com wrote:
> > -----Original Message-----
> > From: Xinyi Hou <Y_Ashley@163.com>
> > Sent: Sunday, April 9, 2023 6:18 PM
> > To: Kumaravel Thiagarajan - I21417
> > <Kumaravel.Thiagarajan@microchip.com>; Arnd Bergmann
> > <arnd@arndb.de>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >
> > 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.")
> > Signed-off-by: Xinyi Hou <Y_Ashley@163.com>
> > Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
> Reviewed-by: Kumaravel Thiagarajan <kumaravel.thiagarajan@microchip.com>
> > ---
> > 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-20 12:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-09 12:48 [PATCH] misc: mchp_pci1xxxx: mchp_pci1xxxx_gp: add unwind goto Xinyi Hou
2023-04-13 4:43 ` Kumaravel.Thiagarajan
2023-04-20 12:04 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®