2021-07-01 20:19:59

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH net v2 1/2] gve: Fix an error handling path in 'gve_probe()'

If the 'register_netdev() call fails, we must release the resources
allocated by the previous 'gve_init_priv()' call, as already done in the
remove function.

Add a new label and the missing 'gve_teardown_priv_resources()' in the
error handling path.

Fixes: 893ce44df565 ("gve: Add basic driver framework for Compute Engine Virtual NIC")
Signed-off-by: Christophe JAILLET <[email protected]>
---
v2: Fix a typo in the label name
The previous serie had 3 patches. Now their are only 2
---
drivers/net/ethernet/google/gve/gve_main.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c
index 867e87af3432..44262c9f9ec2 100644
--- a/drivers/net/ethernet/google/gve/gve_main.c
+++ b/drivers/net/ethernet/google/gve/gve_main.c
@@ -1565,7 +1565,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)

err = register_netdev(dev);
if (err)
- goto abort_with_wq;
+ goto abort_with_gve_init;

dev_info(&pdev->dev, "GVE version %s\n", gve_version_str);
dev_info(&pdev->dev, "GVE queue format %d\n", (int)priv->queue_format);
@@ -1573,6 +1573,9 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
queue_work(priv->gve_wq, &priv->service_task);
return 0;

+abort_with_gve_init:
+ gve_teardown_priv_resources(priv);
+
abort_with_wq:
destroy_workqueue(priv->gve_wq);

--
2.30.2


2021-07-01 20:23:00

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH net v2 2/2] gve: Propagate error codes to caller

If 'gve_probe()' fails, we should propagate the error code, instead of
hard coding a -ENXIO value.
Make sure that all error handling paths set a correct value for 'err'.

Signed-off-by: Christophe JAILLET <[email protected]>
---
v2: Unchanged
The previous serie had 3 patches. Now their are only 2
---
drivers/net/ethernet/google/gve/gve_main.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c
index 44262c9f9ec2..c03984b26db4 100644
--- a/drivers/net/ethernet/google/gve/gve_main.c
+++ b/drivers/net/ethernet/google/gve/gve_main.c
@@ -1469,7 +1469,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)

err = pci_enable_device(pdev);
if (err)
- return -ENXIO;
+ return err;

err = pci_request_regions(pdev, "gvnic-cfg");
if (err)
@@ -1512,6 +1512,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
dev = alloc_etherdev_mqs(sizeof(*priv), max_tx_queues, max_rx_queues);
if (!dev) {
dev_err(&pdev->dev, "could not allocate netdev\n");
+ err = -ENOMEM;
goto abort_with_db_bar;
}
SET_NETDEV_DEV(dev, &pdev->dev);
@@ -1593,7 +1594,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)

abort_with_enabled:
pci_disable_device(pdev);
- return -ENXIO;
+ return err;
}

static void gve_remove(struct pci_dev *pdev)
--
2.30.2

2021-07-01 20:56:15

by Catherine Sullivan

[permalink] [raw]
Subject: Re: [PATCH net v2 1/2] gve: Fix an error handling path in 'gve_probe()'

On Thu, Jul 1, 2021 at 1:18 PM Christophe JAILLET
<[email protected]> wrote:
>
> If the 'register_netdev() call fails, we must release the resources
> allocated by the previous 'gve_init_priv()' call, as already done in the
> remove function.
>
> Add a new label and the missing 'gve_teardown_priv_resources()' in the
> error handling path.
>
> Fixes: 893ce44df565 ("gve: Add basic driver framework for Compute Engine Virtual NIC")
> Signed-off-by: Christophe JAILLET <[email protected]>

Reviewed-by: Catherine Sullivan <[email protected]>

> ---
> v2: Fix a typo in the label name
> The previous serie had 3 patches. Now their are only 2
> ---
> drivers/net/ethernet/google/gve/gve_main.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c
> index 867e87af3432..44262c9f9ec2 100644
> --- a/drivers/net/ethernet/google/gve/gve_main.c
> +++ b/drivers/net/ethernet/google/gve/gve_main.c
> @@ -1565,7 +1565,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>
> err = register_netdev(dev);
> if (err)
> - goto abort_with_wq;
> + goto abort_with_gve_init;
>
> dev_info(&pdev->dev, "GVE version %s\n", gve_version_str);
> dev_info(&pdev->dev, "GVE queue format %d\n", (int)priv->queue_format);
> @@ -1573,6 +1573,9 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> queue_work(priv->gve_wq, &priv->service_task);
> return 0;
>
> +abort_with_gve_init:
> + gve_teardown_priv_resources(priv);
> +
> abort_with_wq:
> destroy_workqueue(priv->gve_wq);
>
> --
> 2.30.2
>

Thanks for the fix!

2021-07-01 20:58:24

by Catherine Sullivan

[permalink] [raw]
Subject: Re: [PATCH net v2 2/2] gve: Propagate error codes to caller

On Thu, Jul 1, 2021 at 1:18 PM Christophe JAILLET
<[email protected]> wrote:
>
> If 'gve_probe()' fails, we should propagate the error code, instead of
> hard coding a -ENXIO value.
> Make sure that all error handling paths set a correct value for 'err'.
>
> Signed-off-by: Christophe JAILLET <[email protected]>

Reviewed-by: Catherine Sullivan <[email protected]>

> ---
> v2: Unchanged
> The previous serie had 3 patches. Now their are only 2
> ---
> drivers/net/ethernet/google/gve/gve_main.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c
> index 44262c9f9ec2..c03984b26db4 100644
> --- a/drivers/net/ethernet/google/gve/gve_main.c
> +++ b/drivers/net/ethernet/google/gve/gve_main.c
> @@ -1469,7 +1469,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>
> err = pci_enable_device(pdev);
> if (err)
> - return -ENXIO;
> + return err;
>
> err = pci_request_regions(pdev, "gvnic-cfg");
> if (err)
> @@ -1512,6 +1512,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> dev = alloc_etherdev_mqs(sizeof(*priv), max_tx_queues, max_rx_queues);
> if (!dev) {
> dev_err(&pdev->dev, "could not allocate netdev\n");
> + err = -ENOMEM;
> goto abort_with_db_bar;
> }
> SET_NETDEV_DEV(dev, &pdev->dev);
> @@ -1593,7 +1594,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>
> abort_with_enabled:
> pci_disable_device(pdev);
> - return -ENXIO;
> + return err;
> }
>
> static void gve_remove(struct pci_dev *pdev)
> --
> 2.30.2
>

Thanks for the fix!

2021-07-01 22:52:24

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net v2 1/2] gve: Fix an error handling path in 'gve_probe()'

Hello:

This series was applied to netdev/net.git (refs/heads/master):

On Thu, 1 Jul 2021 22:18:24 +0200 you wrote:
> If the 'register_netdev() call fails, we must release the resources
> allocated by the previous 'gve_init_priv()' call, as already done in the
> remove function.
>
> Add a new label and the missing 'gve_teardown_priv_resources()' in the
> error handling path.
>
> [...]

Here is the summary with links:
- [net,v2,1/2] gve: Fix an error handling path in 'gve_probe()'
https://git.kernel.org/netdev/net/c/2342ae10d127
- [net,v2,2/2] gve: Propagate error codes to caller
https://git.kernel.org/netdev/net/c/6dce38b4b7ff

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html