Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2133301iof; Tue, 7 Jun 2022 20:51:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywmUgP3/fZW/SHKGbRoZcdqXivNCESWXReBQhfW4JTwMXQeTSm2KpwKbAwfWOo4CUp2meM X-Received: by 2002:a63:2cd0:0:b0:3fe:2810:ba99 with SMTP id s199-20020a632cd0000000b003fe2810ba99mr2093718pgs.27.1654660302911; Tue, 07 Jun 2022 20:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654660302; cv=none; d=google.com; s=arc-20160816; b=fUABQwouc/dZrayU/LcyjlmzEGz+IHcdTktx2/zqWgDu/sh4iUKQn2Sgaw8avFHoNE Lq9IIFeB2bIqQ7juhbBESb4CCTiN2v7Y/Huw9WQlbCfvkzWu+eEGJbp+HMbMGFVJaYZ3 AyV4wwwMcejtRqjWdswRjkw4vfELOfn82ZRA+O6rqe1fjKPoAqa+/LxKE12ACbbIx/bG eofp/wwnO5w0qVKPic8p2vQdjToxDncOWdZteOgyX7Ua3NrQrysMqZ7jqpeSGfZ6UHwC XpYiDlV2HpY/RpDWXeymxaCFo5hz2p96t85S3coiR3XAji6SHBqpa/V6GJYsyA4UGBQw LdFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=pniHEHRrB59YTtTNBTHlm1oMkttAh1nN6oBL1H5yKWM=; b=nmDvLPgSTsqsDNFZnhTM1oEHf7U4SZrPdjEexhXACSvIPSIgbWvQJMwzUsdBqX9bH2 7cY0vMg0vSWWfvTDZI6yrmPPz1raXlJgYHBJElr3N4RS8xT40E5Bt+EFbVY7D/dDozRP h5S8usku7yD3HSQ0VAqUQJHZCJZTpvvn1p6Bq4OCeUoOj7IDNqjek1/vqd5UPlpBkCFm NGTLvZIgOphRzzN84bO62wK/dsSSF60USmglb4xaxVrxfPZpqYeehVU/a8+4rVo9myLL rZ84rUAbjXCQV+632eu1UBTGGnW4cU1Rmtd4k91lAlZYj6I11jZjbSFBU1/F9w0hGzM0 pQ4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ANVUJX2n; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s11-20020a056a00194b00b00519099107ddsi20497071pfk.234.2022.06.07.20.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 20:51:42 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ANVUJX2n; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C4CD5408A51; Tue, 7 Jun 2022 20:23:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381139AbiFGWjX (ORCPT + 99 others); Tue, 7 Jun 2022 18:39:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379397AbiFGVZd (ORCPT ); Tue, 7 Jun 2022 17:25:33 -0400 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35B62228713; Tue, 7 Jun 2022 12:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1654628511; x=1686164511; h=references:from:to:cc:subject:date:in-reply-to: message-id:mime-version; bh=pniHEHRrB59YTtTNBTHlm1oMkttAh1nN6oBL1H5yKWM=; b=ANVUJX2nD5MBjE4xE8mXlELzhYCcWe/+Jjk6Fn2gQX00oNSvIIJlolKa tVCbgKKGTkwO9bX1MTdvsYvgG2skpgojt3B9HwlKWco+VxO9zz7BSj3DT rBt20It5InNCsLFmj91Vo9HOkGE5fVr0veBOhmgCifeK6q6FGRdyKjOsL 4=; X-IronPort-AV: E=Sophos;i="5.91,284,1647302400"; d="scan'208";a="200518085" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-2d7489a4.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP; 07 Jun 2022 19:01:36 +0000 Received: from EX13D28EUC001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1a-2d7489a4.us-east-1.amazon.com (Postfix) with ESMTPS id 9C7E4A2532; Tue, 7 Jun 2022 19:01:33 +0000 (UTC) Received: from u570694869fb251.ant.amazon.com.amazon.com (10.43.160.26) by EX13D28EUC001.ant.amazon.com (10.43.164.4) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Tue, 7 Jun 2022 19:01:27 +0000 References: <20220607122831.32738-1-xiaohuizhang@ruc.edu.cn> User-agent: mu4e 1.6.10; emacs 28.0.91 From: Shay Agroskin To: Xiaohui Zhang CC: Arthur Kiyanovski , David Arinzon , Noam Dagan , Saeed Bishara , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Sameeh Jubran , , Subject: Re: [PATCH 1/1] net: ena_netdev: fix resource leak Date: Tue, 7 Jun 2022 21:57:43 +0300 In-Reply-To: <20220607122831.32738-1-xiaohuizhang@ruc.edu.cn> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; format=flowed X-Originating-IP: [10.43.160.26] X-ClientProxiedBy: EX13D32UWB003.ant.amazon.com (10.43.161.220) To EX13D28EUC001.ant.amazon.com (10.43.164.4) X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Xiaohui Zhang 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 > --- > 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)