linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wifi: ath10k: Fix resource leak in ath10k_pci_init()
@ 2022-11-08 13:38 Xiu Jianfeng
  2022-11-09 16:34 ` Jeff Johnson
  0 siblings, 1 reply; 4+ messages in thread
From: Xiu Jianfeng @ 2022-11-08 13:38 UTC (permalink / raw)
  To: kvalo, davem, edumazet, kuba, pabeni, rmani
  Cc: ath10k, linux-wireless, linux-kernel

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 <xiujianfeng@huawei.com>
---
 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;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] wifi: ath10k: Fix resource leak in ath10k_pci_init()
  2022-11-08 13:38 [PATCH] wifi: ath10k: Fix resource leak in ath10k_pci_init() Xiu Jianfeng
@ 2022-11-09 16:34 ` Jeff Johnson
  2022-11-10  1:54   ` xiujianfeng
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff Johnson @ 2022-11-09 16:34 UTC (permalink / raw)
  To: Xiu Jianfeng, kvalo, davem, edumazet, kuba, pabeni, rmani
  Cc: ath10k, linux-wireless, linux-kernel

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 <xiujianfeng@huawei.com>
> ---
>   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;
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] wifi: ath10k: Fix resource leak in ath10k_pci_init()
  2022-11-09 16:34 ` Jeff Johnson
@ 2022-11-10  1:54   ` xiujianfeng
  2022-11-10  2:54     ` xiujianfeng
  0 siblings, 1 reply; 4+ messages in thread
From: xiujianfeng @ 2022-11-10  1:54 UTC (permalink / raw)
  To: Jeff Johnson, kvalo, davem, edumazet, kuba, pabeni, rmani
  Cc: ath10k, linux-wireless, linux-kernel

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 <xiujianfeng@huawei.com>
>> ---
>>   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.

> 
> .

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] wifi: ath10k: Fix resource leak in ath10k_pci_init()
  2022-11-10  1:54   ` xiujianfeng
@ 2022-11-10  2:54     ` xiujianfeng
  0 siblings, 0 replies; 4+ messages in thread
From: xiujianfeng @ 2022-11-10  2:54 UTC (permalink / raw)
  To: Jeff Johnson, kvalo, davem, edumazet, kuba, pabeni, rmani
  Cc: ath10k, linux-wireless, linux-kernel

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 <xiujianfeng@huawei.com>
>>> ---
>>>   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.

>>
>> .
> 
> .

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-10  2:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 13:38 [PATCH] wifi: ath10k: Fix resource leak in ath10k_pci_init() Xiu Jianfeng
2022-11-09 16:34 ` Jeff Johnson
2022-11-10  1:54   ` xiujianfeng
2022-11-10  2:54     ` xiujianfeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).