Re: [PATCH] staging: qlge: add unregister_netdev in qlge_probe

Dan Carpenter
2022-02-18T12:04:20Z

On Fri, Feb 18, 2022 at 04:11:30PM +0800, Hangyu Hua wrote:
> unregister_netdev need to be called when register_netdev succeeds
> qlge_health_create_reporters fails.
>

1) Add a Fixes tag:

Fixes: d8827ae8e22b ("staging: qlge: deal with the case that devlink_health_reporter_create fails")

> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---
> drivers/staging/qlge/qlge_main.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/qlge/qlge_main.c b/drivers/staging/qlge/qlge_main.c
> index 9873bb2a9ee4..0a199c6d77a1 100644
> --- a/drivers/staging/qlge/qlge_main.c
> +++ b/drivers/staging/qlge/qlge_main.c
> @@ -4611,8 +4611,10 @@ static int qlge_probe(struct pci_dev *pdev,
> }
>
> err = qlge_health_create_reporters(qdev);
> - if (err)
> + if (err) {
> + unregister_netdev(ndev);
> goto netdev_free;
> + }

2) Use a goto to unwind. 3) Release the other pdev stuff as well.
4) Clean up the error handling for register_netdev() by using a goto
as well.

err = register_netdev(ndev);
if (err) {
dev_err(&pdev->dev, "net device registration failed.\n");
goto cleanup_pdev;
}

err = qlge_health_create_reporters(qdev);
if (err)
goto unregister_netdev;

...

return 0;

unregister_netdev:
unregister_netdev(ndev);
cleanup_pdev:
qlge_release_all(pdev);
pci_disable_device(pdev);
netdev_free:
free_netdev(ndev);
devlink_free:
devlink_free(devlink);

return ret;

regards,
dan carpenter