All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root
@ 2024-08-31  5:21 Wentao Guan
  2024-08-31  7:18 ` Huacai Chen
  0 siblings, 1 reply; 6+ messages in thread
From: Wentao Guan @ 2024-08-31  5:21 UTC (permalink / raw)
  To: henhuacai, kernel, loongarch; +Cc: linux-kernel, Wentao Guan, Wangyuli

Add kfree(root_ops) in this case to avoid memleak root_ops,
leaks when pci_find_bus() != 0.
Also delay assign root_ops when used for making code read clean.
Found by code review

Signed-off-by: Wangyuli <wangyuli@uniontech.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
---
 arch/loongarch/pci/acpi.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/loongarch/pci/acpi.c b/arch/loongarch/pci/acpi.c
index 3eb61b8cd5e3..7f3539f5fa23 100644
--- a/arch/loongarch/pci/acpi.c
+++ b/arch/loongarch/pci/acpi.c
@@ -219,17 +219,18 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
 		return NULL;
 	}
 
-	root_ops->release_info = acpi_release_root_info;
-	root_ops->prepare_resources = acpi_prepare_root_resources;
-	root_ops->pci_ops = (struct pci_ops *)&info->cfg->ops->pci_ops;
-
 	bus = pci_find_bus(domain, busnum);
 	if (bus) {
 		memcpy(bus->sysdata, info->cfg, sizeof(struct pci_config_window));
 		kfree(info);
+		kfree(root_ops);
 	} else {
 		struct pci_bus *child;
 
+		root_ops->release_info = acpi_release_root_info;
+		root_ops->prepare_resources = acpi_prepare_root_resources;
+		root_ops->pci_ops = (struct pci_ops *)&info->cfg->ops->pci_ops;
+
 		bus = acpi_pci_root_create(root, root_ops,
 					   &info->common, info->cfg);
 		if (!bus) {
-- 
2.20.1


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

* Re: [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root
  2024-08-31  5:21 [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root Wentao Guan
@ 2024-08-31  7:18 ` Huacai Chen
  2024-08-31  7:30   ` Wentao Guan
  2024-08-31  7:40   ` WangYuli
  0 siblings, 2 replies; 6+ messages in thread
From: Huacai Chen @ 2024-08-31  7:18 UTC (permalink / raw)
  To: Wentao Guan; +Cc: henhuacai, kernel, loongarch, linux-kernel, Wangyuli

Hi, Wentao,

On Sat, Aug 31, 2024 at 1:24 PM Wentao Guan <guanwentao@uniontech.com> wrote:
>
> Add kfree(root_ops) in this case to avoid memleak root_ops,
> leaks when pci_find_bus() != 0.
> Also delay assign root_ops when used for making code read clean.
> Found by code review
>
> Signed-off-by: Wangyuli <wangyuli@uniontech.com>
This should be Yuli Wang <wangyuli@uniontech.com>

> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
> ---
>  arch/loongarch/pci/acpi.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/arch/loongarch/pci/acpi.c b/arch/loongarch/pci/acpi.c
> index 3eb61b8cd5e3..7f3539f5fa23 100644
> --- a/arch/loongarch/pci/acpi.c
> +++ b/arch/loongarch/pci/acpi.c
> @@ -219,17 +219,18 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
>                 return NULL;
>         }
>
> -       root_ops->release_info = acpi_release_root_info;
> -       root_ops->prepare_resources = acpi_prepare_root_resources;
> -       root_ops->pci_ops = (struct pci_ops *)&info->cfg->ops->pci_ops;
> -
>         bus = pci_find_bus(domain, busnum);
>         if (bus) {
>                 memcpy(bus->sysdata, info->cfg, sizeof(struct pci_config_window));
>                 kfree(info);
> +               kfree(root_ops);
Add kfree() is fine, but move root_ops assignment is unnecessary.

Huacai

>         } else {
>                 struct pci_bus *child;
>
> +               root_ops->release_info = acpi_release_root_info;
> +               root_ops->prepare_resources = acpi_prepare_root_resources;
> +               root_ops->pci_ops = (struct pci_ops *)&info->cfg->ops->pci_ops;
> +
>                 bus = acpi_pci_root_create(root, root_ops,
>                                            &info->common, info->cfg);
>                 if (!bus) {
> --
> 2.20.1
>
>

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

* Re: [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root
  2024-08-31  7:18 ` Huacai Chen
@ 2024-08-31  7:30   ` Wentao Guan
  2024-08-31  8:35     ` Wentao Guan
  2024-08-31  7:40   ` WangYuli
  1 sibling, 1 reply; 6+ messages in thread
From: Wentao Guan @ 2024-08-31  7:30 UTC (permalink / raw)
  To: Huacai Chen
  Cc: WANG Xuerui, loongarch, linux-kernel, 王昱力

Hello Huacai:

Okay... It is my code smell, here is the patch after change.

From 73426019a83a77b4502491fc96d145e666b16936 Mon Sep 17 00:00:00 2001
From: Wentao Guan <guanwentao@uniontech.com>
Date: Sat, 31 Aug 2024 00:17:10 +0800
Subject: [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root

Add kfree(root_ops) in this case to avoid memleak root_ops,
leaks when pci_find_bus() != 0.

Signed-off-by: Wangyuli <wangyuli@uniontech.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
---
 arch/loongarch/pci/acpi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/loongarch/pci/acpi.c b/arch/loongarch/pci/acpi.c
index 3eb61b8cd5e3..f405409a3491 100644
--- a/arch/loongarch/pci/acpi.c
+++ b/arch/loongarch/pci/acpi.c
@@ -227,6 +227,7 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
        if (bus) {
                memcpy(bus->sysdata, info->cfg, sizeof(struct pci_config_window));
                kfree(info);
+               kfree(root_ops);
        } else {
                struct pci_bus *child;
 
-- 
2.20.1

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

* Re: [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root
  2024-08-31  7:18 ` Huacai Chen
  2024-08-31  7:30   ` Wentao Guan
@ 2024-08-31  7:40   ` WangYuli
  1 sibling, 0 replies; 6+ messages in thread
From: WangYuli @ 2024-08-31  7:40 UTC (permalink / raw)
  To: Huacai Chen, Wentao Guan; +Cc: henhuacai, kernel, loongarch, linux-kernel


On 2024/8/31 15:18, Huacai Chen wrote:
> Hi, Wentao,
>
> On Sat, Aug 31, 2024 at 1:24 PM Wentao Guan <guanwentao@uniontech.com> wrote:
>> Add kfree(root_ops) in this case to avoid memleak root_ops,
>> leaks when pci_find_bus() != 0.
>> Also delay assign root_ops when used for making code read clean.
>> Found by code review
>>
>> Signed-off-by: Wangyuli <wangyuli@uniontech.com>
> This should be Yuli Wang <wangyuli@uniontech.com>

While I maintain a preference for the traditional Chinese naming order, 
not particularly like putting my Chinese name in the English surname order,

I acknowledge that flexibility in this matter is often necessary.

It is sufficient for everybody to be aware that both 'WangYuli' and 
'Yuli Wang' refer to me.

>> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
>> ---
>>   arch/loongarch/pci/acpi.c | 9 +++++----
>>   1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/loongarch/pci/acpi.c b/arch/loongarch/pci/acpi.c
>> index 3eb61b8cd5e3..7f3539f5fa23 100644
>> --- a/arch/loongarch/pci/acpi.c
>> +++ b/arch/loongarch/pci/acpi.c
>> @@ -219,17 +219,18 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
>>                  return NULL;
>>          }
>>
>> -       root_ops->release_info = acpi_release_root_info;
>> -       root_ops->prepare_resources = acpi_prepare_root_resources;
>> -       root_ops->pci_ops = (struct pci_ops *)&info->cfg->ops->pci_ops;
>> -
>>          bus = pci_find_bus(domain, busnum);
>>          if (bus) {
>>                  memcpy(bus->sysdata, info->cfg, sizeof(struct pci_config_window));
>>                  kfree(info);
>> +               kfree(root_ops);
> Add kfree() is fine, but move root_ops assignment is unnecessary.
>
> Huacai
>
>>          } else {
>>                  struct pci_bus *child;
>>
>> +               root_ops->release_info = acpi_release_root_info;
>> +               root_ops->prepare_resources = acpi_prepare_root_resources;
>> +               root_ops->pci_ops = (struct pci_ops *)&info->cfg->ops->pci_ops;
>> +
>>                  bus = acpi_pci_root_create(root, root_ops,
>>                                             &info->common, info->cfg);
>>                  if (!bus) {
>> --
>> 2.20.1
>>
>>
-- 
WangYuli


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

* Re: [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root
  2024-08-31  7:30   ` Wentao Guan
@ 2024-08-31  8:35     ` Wentao Guan
  2024-08-31 12:37       ` Huacai Chen
  0 siblings, 1 reply; 6+ messages in thread
From: Wentao Guan @ 2024-08-31  8:35 UTC (permalink / raw)
  To: chenhuacai; +Cc: WANG Xuerui, loongarch, linux-kernel, 王昱力

Hello Huacai:

I found a mistake that my PATCH commit msg need change to "Loongarch: pci: fix memleak in pci_acpi_scan_root"
Need to send patch v2?

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

* Re: [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root
  2024-08-31  8:35     ` Wentao Guan
@ 2024-08-31 12:37       ` Huacai Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Huacai Chen @ 2024-08-31 12:37 UTC (permalink / raw)
  To: Wentao Guan
  Cc: WANG Xuerui, loongarch, linux-kernel, 王昱力

On Sat, Aug 31, 2024 at 4:36 PM Wentao Guan <guanwentao@uniontech.com> wrote:
>
> Hello Huacai:
>
> I found a mistake that my PATCH commit msg need change to "Loongarch: pci: fix memleak in pci_acpi_scan_root"
> Need to send patch v2?
No need.

Huacai

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

end of thread, other threads:[~2024-08-31 12:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-31  5:21 [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root Wentao Guan
2024-08-31  7:18 ` Huacai Chen
2024-08-31  7:30   ` Wentao Guan
2024-08-31  8:35     ` Wentao Guan
2024-08-31 12:37       ` Huacai Chen
2024-08-31  7:40   ` WangYuli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.