Re: [PATCH 1/1] net: ena_netdev: fix resource leak

From: Shay Agroskin
Date: Tue Jun 07 2022 - 18:39:32 EST



Xiaohui Zhang <xiaohuizhang@xxxxxxxxxx> writes:

Similar to the handling of u132_hcd_init in commit f276e002793c
("usb: u132-hcd: fix resource leak"), we thought a patch might be
needed here as well.

If platform_driver_register fails, cleanup the allocated resource
gracefully.

Signed-off-by: Xiaohui Zhang <xiaohuizhang@xxxxxxxxxx>
---
drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

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

Hi,
thanks a lot for this patch. I made a few small changes in it to make it more consistent with the rest of driver's code
(sorry don't really know how to insert an inline diff)

thanks,
Shay

---
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 6a356a6cee15..be8d3c26c9bb 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -4545,13 +4545,19 @@ static struct pci_driver ena_pci_driver = {

static int __init ena_init(void)
{
+ int rc;
+
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);
+ rc = pci_register_driver(&ena_pci_driver);
+ if (rc)
+ destroy_workqueue(ena_wq);
+
+ return rc;
}

static void __exit ena_cleanup(void)