Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1194rwb; Wed, 9 Nov 2022 18:55:08 -0800 (PST) X-Google-Smtp-Source: AMsMyM7CjklVtKOqN8c4I5ylEPz/ftxm0LfLpZvgExrSr3BrTMSl9IhdqrptTVMvyPINE01Wf8Ah X-Received: by 2002:a17:902:768c:b0:186:b136:187a with SMTP id m12-20020a170902768c00b00186b136187amr61745397pll.94.1668048907791; Wed, 09 Nov 2022 18:55:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668048907; cv=none; d=google.com; s=arc-20160816; b=Qht76LWOcjNpA+Br3g29LgzmLREsdh42De+IVnW2dcI74s19bXJxbyfW4gdXXywX8o GKUECOarpl7E/K65ftqFYqai0D2kZ+5XEb+nM8x1mZvvSKCZj07AxUy1dRlTmnK0XSFk bK9rjvCB/IMJYi8kYZ99RUSRloXh52LVBv/Due4JYX1p//ZYrggO5m+b+Pg2VI7vfboZ bpRNMPEQWBl1k/W8Xnxi0CYyMwHs/KoB5LUTJjLBqTha49EYrifo9AQP2Ov7uxPPAv42 fIgvLCJB54hhueYJcfQzQuFEAiN/im1aqcHZ3HwZ/I2CkckKEtS69Gz3vgRy00/uTRa5 QJPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:references:cc:to:from :subject; bh=WmsAPf4w3cXkwG5pCmhq2y/QG6e4UnoIx4RkbXwE6uc=; b=VEjk2hXIQeEQDCPETwTGkEHhUXTmZEygYJz6L/3TtSkOSvu4A9KACZQtnB6i/xqBaw aXMV4sNsSnUjUkHhWoqLXseXfoYVr+7sIy97E4L/qRg4/euwBdf7+aJBBcotuafEXHUr Ttwao45oTuzGjKKlEkxLwQji1LF2oPupcdRJkxa8b1lKnbZpweS1SVU8DK2tjjuV6/gP kcYn+WyEyOiOUqK2yibHpkdDd6hhV14xE1yF69Q2KzZvbZavcuuMFRh0BjZ2o2EeRYue vGtogAKLFw04FcIibrZRfUqi/C2Z7MXUSjgyQH7UzTxzvYHs3KI3ijOoDTyS5gA0h5e/ mo+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ip7-20020a17090b314700b00205ee3e845bsi3269439pjb.116.2022.11.09.18.54.32; Wed, 09 Nov 2022 18:55:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232558AbiKJCyO (ORCPT + 66 others); Wed, 9 Nov 2022 21:54:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231769AbiKJCyN (ORCPT ); Wed, 9 Nov 2022 21:54:13 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 837BD23BD8; Wed, 9 Nov 2022 18:54:12 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N75yF3pdSz15MS4; Thu, 10 Nov 2022 10:53:57 +0800 (CST) Received: from [10.67.110.112] (10.67.110.112) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 10 Nov 2022 10:54:10 +0800 Subject: Re: [PATCH] wifi: ath10k: Fix resource leak in ath10k_pci_init() From: xiujianfeng To: Jeff Johnson , , , , , , CC: , , References: <20221108133858.53308-1-xiujianfeng@huawei.com> <4e81efea-23f1-e52c-b0b4-abf445ed5f15@quicinc.com> Message-ID: Date: Thu, 10 Nov 2022 10:54:10 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.112] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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-wireless@vger.kernel.org Hi, 在 2022/11/10 9:54, xiujianfeng 写道: > Hi, > > 在 2022/11/10 0:34, Jeff Johnson 写道: >> On 11/8/2022 5:38 AM, Xiu Jianfeng wrote: >>> When ath10k_ahb_init() fails, it does not unregister ath10k_pci_driver, >>> which will cause a resource leak issue, call pci_unregister_driver() in >>> the error path to fix this issue. >>> >>> Fixes: 0b523ced9a3c ("ath10k: add basic skeleton to support ahb") >>> Signed-off-by: Xiu Jianfeng >>> --- >>>   drivers/net/wireless/ath/ath10k/pci.c | 4 +++- >>>   1 file changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/net/wireless/ath/ath10k/pci.c >>> b/drivers/net/wireless/ath/ath10k/pci.c >>> index e56c6a6b1379..22f8f8b20762 100644 >>> --- a/drivers/net/wireless/ath/ath10k/pci.c >>> +++ b/drivers/net/wireless/ath/ath10k/pci.c >>> @@ -3800,8 +3800,10 @@ static int __init ath10k_pci_init(void) >>>                  ret); >>>       ret = ath10k_ahb_init(); >>> -    if (ret) >>> +    if (ret) { >>>           printk(KERN_ERR "ahb init failed: %d\n", ret); >>> +        pci_unregister_driver(&ath10k_pci_driver); >>> +    } >>>       return ret; >>>   } >> >> imo neither the existing code nor the modified code is correct. >> >> the driver is attempting to register to support two different buses. >> >> if either of these is successful then ath10k_pci_init() should return >> 0 so that hardware attached to the successful bus can be probed and >> supported. >> >> only if both of these are unsuccessful should ath10k_pci_init() return >> an errno. >> >> so I suggest >>      int ret1, ret2; >> >>      ret1 = pci_register_driver(&ath10k_pci_driver); >>      if (ret1) >>          printk(KERN_ERR "failed to register ath10k pci driver: %d\n", >>                 ret1); >> >>      ret2 = ath10k_ahb_init(); >>      if (ret2) >>          printk(KERN_ERR "ahb init failed: %d\n", ret2); >> >>      if (ret1 && ret2) >>          return ret1; >> >>      /* registered to at least one bus */ >>      return 0; >> } > > Thanks, this is better. however, if pci_register_driver() returns 0 > while ath10k_ahb_init() returns error, it's better to unregister the > first bus, here is my another proposal: > >        int ret; > >        ret = pci_register_driver(&ath10k_pci_driver); >        if (ret) { >                printk(KERN_ERR "failed to register ath10k pci driver: > %d\n", >                       ret); >                return ret; >        } > >        ret = ath10k_ahb_init(); >        if (ret) { >                printk(KERN_ERR "ahb init failed: %d\n", ret); >                pci_unregister_driver(&ath10k_pci_driver); >                return ret; >        } > >        return 0; > > If you agree, I will send v2 with this. > Sorry, I misunderstood, I will send v2 according to your suggestion. >> >> . > > .