Skip to contentSkip to conversation

driver: net: can: delete napi if register_candev fails

PATCH In review Dongliang Mu 2 participants 5 messages Oct 13, 2021 – Oct 17, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver: net: can: delete napi if register_candev fails

If register_candev fails, xcan_probe does not clean the napi created by netif_napi_add.

Fix this by adding error handling code to clean napi when register_candev fails.

---
 drivers/net/can/xilinx_can.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/can/xilinx_can.c +3 -1
index 3b883e607d8b..6ee0b5a8cdfc 100644
@@ -1807,7 +1807,7 @@ static int xcan_probe(struct platform_device *pdev)
 	ret = register_candev(ndev);
 	if (ret) {
 		dev_err(&pdev->dev, "fail to register failed (err=%d)\n", ret);
-		goto err_disableclks;
+		goto err_del_napi;
 	}
 
 	devm_can_led_init(ndev);
@@ -1825,6 +1825,8 @@ static int xcan_probe(struct platform_device *pdev)
 
 	return 0;
 
+err_del_napi:
+	netif_napi_del(&priv->napi);
 err_disableclks:
 	pm_runtime_put(priv->dev);
 	pm_runtime_disable(&pdev->dev);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 4 lines · Dongliang Mu

If register_candev fails, xcan_probe does not clean the napi created by netif_napi_add.

It seems the netif_napi_del operation is done in the free_candev (free_netdev precisely).

list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)

          netif_napi_del(p);

And list_add_rcu(&napi->dev_list, &dev->napi_list) is done in the netif_napi_add.

Therefore, I suggest removing "netif_napi_del" operation in the xcan_remove to match probe and remove function.

Quoted 33 lines

Fix this by adding error handling code to clean napi when register_candev fails.

---
 drivers/net/can/xilinx_can.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/can/xilinx_can.c +3 -2
index 3b883e607d8b..6ee0b5a8cdfc 100644
@@ -1807,7 +1807,7 @@ static int xcan_probe(struct platform_device *pdev)
        ret = register_candev(ndev);
        if (ret) {
                dev_err(&pdev->dev, "fail to register failed (err=%d)\n", ret);
-               goto err_disableclks;
+               goto err_del_napi;
        }
 
        devm_can_led_init(ndev);
@@ -1825,6 +1825,8 @@ static int xcan_probe(struct platform_device *pdev)
 
        return 0;
 
+err_del_napi:
+       netif_napi_del(&priv->napi);
 err_disableclks:
        pm_runtime_put(priv->dev);
        pm_runtime_disable(&pdev->dev);
--

2.25.1

#2 lore raw
Quoted 9 lines · Dongliang Mu
Quoted 4 lines · Dongliang Mu

If register_candev fails, xcan_probe does not clean the napi created by netif_napi_add.

It seems the netif_napi_del operation is done in the free_candev (free_netdev precisely).

Quoted 8 lines

list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)

          netif_napi_del(p);

And list_add_rcu(&napi->dev_list, &dev->napi_list) is done in the netif_napi_add.

Therefore, I suggest removing "netif_napi_del" operation in the xcan_remove to match probe and remove function.

Sounds reasonable, can you create a patch for this.

regards,
Marc

Signature · 4 lines
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 |
#3 lore raw
Quoted 14 lines · Marc Kleine-Budde
Quoted 12 lines · Dongliang Mu
Quoted 4 lines · Dongliang Mu

If register_candev fails, xcan_probe does not clean the napi created by netif_napi_add.

It seems the netif_napi_del operation is done in the free_candev (free_netdev precisely).

list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)

          netif_napi_del(p);
Quoted 7 lines
Quoted 5 lines

And list_add_rcu(&napi->dev_list, &dev->napi_list) is done in the netif_napi_add.

Therefore, I suggest removing "netif_napi_del" operation in the xcan_remove to match probe and remove function.

Sounds reasonable, can you create a patch for this.

I have submitted one patch - https://lkml.org/lkml/2021/10/17/181

Quoted 9 lines

regards,
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 |
#4 lore raw
Quoted 18 lines · Dongliang Mu
Quoted 17 lines · Marc Kleine-Budde
Quoted 15 lines · Dongliang Mu
Quoted 4 lines · Dongliang Mu

If register_candev fails, xcan_probe does not clean the napi created by netif_napi_add.

It seems the netif_napi_del operation is done in the free_candev (free_netdev precisely).

list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)

          netif_napi_del(p);

And list_add_rcu(&napi->dev_list, &dev->napi_list) is done in the netif_napi_add.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Therefore, I suggest removing "netif_napi_del" operation in the xcan_remove to match probe and remove function.

Sounds reasonable, can you create a patch for this.

I have submitted one patch - https://lkml.org/lkml/2021/10/17/181

Thanks for the patch.

Regards,
Marc

BTW: Do you know the new kernel.org mailing list archive available at
https://lore.kernel.org ?
You can reference a mail using its Message-ID, in you case it's:
https://lore.kernel.org/all/[email protected]

Signature · 4 lines
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 |