2022-10-24 09:10:31

by Dongliang Mu

[permalink] [raw]
Subject: [PATCH v2] can: mcp251x: fix error handling code in mcp251x_can_probe

In mcp251x_can_probe, if mcp251x_gpio_setup fails, it forgets to
unregister the can device.

Fix this by unregistering can device in mcp251x_can_probe.

Fixes: 2d52dabbef60 ("can: mcp251x: add GPIO support")
Signed-off-by: Dongliang Mu <[email protected]>
---
v1->v2: add fixes tag
drivers/net/can/spi/mcp251x.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index c320de474f40..00ed46683656 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -1415,11 +1415,14 @@ static int mcp251x_can_probe(struct spi_device *spi)

ret = mcp251x_gpio_setup(priv);
if (ret)
- goto error_probe;
+ goto err_reg_candev;

netdev_info(net, "MCP%x successfully initialized.\n", priv->model);
return 0;

+err_reg_candev:
+ unregister_candev(net);
+
error_probe:
destroy_workqueue(priv->wq);
priv->wq = NULL;
--
2.35.1


2022-10-25 08:06:37

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH v2] can: mcp251x: fix error handling code in mcp251x_can_probe

On 24.10.2022 17:02:52, Dongliang Mu wrote:
> In mcp251x_can_probe, if mcp251x_gpio_setup fails, it forgets to
> unregister the can device.
>
> Fix this by unregistering can device in mcp251x_can_probe.
>
> Fixes: 2d52dabbef60 ("can: mcp251x: add GPIO support")
> Signed-off-by: Dongliang Mu <[email protected]>

Applied to can/main.

Thanks,
Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |


Attachments:
(No filename) (634.00 B)
signature.asc (499.00 B)
Download all attachments