diff mbox series

net: ena: Fix error handling in ena_init()

Message ID 20221114025659.124726-1-yuancan@huawei.com (mailing list archive)
State Accepted
Commit d349e9be5a2c2d7588a2c4e4bfa0bb3dc1226769
Delegated to: Netdev Maintainers
Headers show
Series net: ena: Fix error handling in ena_init() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yuan Can Nov. 14, 2022, 2:56 a.m. UTC
The ena_init() won't destroy workqueue created by
create_singlethread_workqueue() when pci_register_driver() failed.
Call destroy_workqueue() when pci_register_driver() failed to prevent the
resource leak.

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Shay Agroskin Nov. 15, 2022, 11:47 a.m. UTC | #1
Yuan Can <yuancan@huawei.com> writes:

> The ena_init() won't destroy workqueue created by
> create_singlethread_workqueue() when pci_register_driver() 
> failed.
> Call destroy_workqueue() when pci_register_driver() failed to 
> prevent the
> resource leak.
>
> Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic 
> Network Adapters (ENA)")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
>  drivers/net/ethernet/amazon/ena/ena_netdev.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
> b/drivers/net/ethernet/amazon/ena/ena_netdev.c
> index d350eeec8bad..5a454b58498f 100644
> --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
> +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
> @@ -4543,13 +4543,19 @@ static struct pci_driver ena_pci_driver 
> = {
>  
>  static int __init ena_init(void)
>  {
> +	int ret;
> +
>  	ena_wq = create_singlethread_workqueue(DRV_MODULE_NAME);
>  	if (!ena_wq) {
>  		pr_err("Failed to create workqueue\n");
>  		return -ENOMEM;
>  	}
>  
> -	return pci_register_driver(&ena_pci_driver);
> +	ret = pci_register_driver(&ena_pci_driver);
> +	if (ret)
> +		destroy_workqueue(ena_wq);
> +
> +	return ret;
>  }
>  
>  static void __exit ena_cleanup(void)

Lgtm. Thanks for this fix.
Acked-by: Shay Agroskin <shayagr@amazon.com>
patchwork-bot+netdevbpf@kernel.org Nov. 15, 2022, noon UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Mon, 14 Nov 2022 02:56:59 +0000 you wrote:
> The ena_init() won't destroy workqueue created by
> create_singlethread_workqueue() when pci_register_driver() failed.
> Call destroy_workqueue() when pci_register_driver() failed to prevent the
> resource leak.
> 
> Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> 
> [...]

Here is the summary with links:
  - net: ena: Fix error handling in ena_init()
    https://git.kernel.org/netdev/net/c/d349e9be5a2c

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index d350eeec8bad..5a454b58498f 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -4543,13 +4543,19 @@  static struct pci_driver ena_pci_driver = {
 
 static int __init ena_init(void)
 {
+	int ret;
+
 	ena_wq = create_singlethread_workqueue(DRV_MODULE_NAME);
 	if (!ena_wq) {
 		pr_err("Failed to create workqueue\n");
 		return -ENOMEM;
 	}
 
-	return pci_register_driver(&ena_pci_driver);
+	ret = pci_register_driver(&ena_pci_driver);
+	if (ret)
+		destroy_workqueue(ena_wq);
+
+	return ret;
 }
 
 static void __exit ena_cleanup(void)