2022-06-06 05:50:50

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH] cxl: Fix refcount leak in cxl_calc_capp_routing

of_get_next_parent() returns a node pointer with refcount incremented,
we should use of_node_put() on it when not need anymore.
This function only calls of_node_put() in normal path,
missing it in the error path.
Add missing of_node_put() to avoid refcount leak.

Fixes: f24be42aab37 ("cxl: Add psl9 specific code")
Signed-off-by: Miaoqian Lin <[email protected]>
---
drivers/misc/cxl/pci.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index 3de0aea62ade..62385a529d86 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev, u64 *chipid,
rc = get_phb_index(np, phb_index);
if (rc) {
pr_err("cxl: invalid phb index\n");
+ of_node_put(np);
return rc;
}

--
2.25.1


2022-06-08 05:48:32

by Frederic Barrat

[permalink] [raw]
Subject: Re: [PATCH] cxl: Fix refcount leak in cxl_calc_capp_routing



On 05/06/2022 08:00, Miaoqian Lin wrote:
> of_get_next_parent() returns a node pointer with refcount incremented,
> we should use of_node_put() on it when not need anymore.
> This function only calls of_node_put() in normal path,
> missing it in the error path.
> Add missing of_node_put() to avoid refcount leak.
>
> Fixes: f24be42aab37 ("cxl: Add psl9 specific code")
> Signed-off-by: Miaoqian Lin <[email protected]>


Indeed. Thanks!
Acked-by: Frederic Barrat <[email protected]>

Fred


> ---
> drivers/misc/cxl/pci.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
> index 3de0aea62ade..62385a529d86 100644
> --- a/drivers/misc/cxl/pci.c
> +++ b/drivers/misc/cxl/pci.c
> @@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev, u64 *chipid,
> rc = get_phb_index(np, phb_index);
> if (rc) {
> pr_err("cxl: invalid phb index\n");
> + of_node_put(np);
> return rc;
> }
>

2022-06-14 10:17:45

by Andrew Donnellan

[permalink] [raw]
Subject: Re: [PATCH] cxl: Fix refcount leak in cxl_calc_capp_routing

On Sun, 2022-06-05 at 10:00 +0400, Miaoqian Lin wrote:
> of_get_next_parent() returns a node pointer with refcount
> incremented,
> we should use of_node_put() on it when not need anymore.
> This function only calls of_node_put() in normal path,
> missing it in the error path.
> Add missing of_node_put() to avoid refcount leak.
>
> Fixes: f24be42aab37 ("cxl: Add psl9 specific code")
> Signed-off-by: Miaoqian Lin <[email protected]>

Thanks!

Acked-by: Andrew Donnellan <[email protected]>

> ---
>  drivers/misc/cxl/pci.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
> index 3de0aea62ade..62385a529d86 100644
> --- a/drivers/misc/cxl/pci.c
> +++ b/drivers/misc/cxl/pci.c
> @@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev,
> u64 *chipid,
>         rc = get_phb_index(np, phb_index);
>         if (rc) {
>                 pr_err("cxl: invalid phb index\n");
> +               of_node_put(np);
>                 return rc;
>         }
>  


2022-11-14 13:25:01

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH] cxl: Fix refcount leak in cxl_calc_capp_routing

Should this be applied by Bjorn as most recent changes to that file ?


Le 14/06/2022 à 12:12, Andrew Donnellan a écrit :
> On Sun, 2022-06-05 at 10:00 +0400, Miaoqian Lin wrote:
>> of_get_next_parent() returns a node pointer with refcount
>> incremented,
>> we should use of_node_put() on it when not need anymore.
>> This function only calls of_node_put() in normal path,
>> missing it in the error path.
>> Add missing of_node_put() to avoid refcount leak.
>>
>> Fixes: f24be42aab37 ("cxl: Add psl9 specific code")
>> Signed-off-by: Miaoqian Lin <[email protected]>
>
> Thanks!
>
> Acked-by: Andrew Donnellan <[email protected]>
>
>> ---
>>  drivers/misc/cxl/pci.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
>> index 3de0aea62ade..62385a529d86 100644
>> --- a/drivers/misc/cxl/pci.c
>> +++ b/drivers/misc/cxl/pci.c
>> @@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev,
>> u64 *chipid,
>>         rc = get_phb_index(np, phb_index);
>>         if (rc) {
>>                 pr_err("cxl: invalid phb index\n");
>> +               of_node_put(np);
>>                 return rc;
>>         }
>>
>
>

2022-11-22 05:57:11

by Andrew Donnellan

[permalink] [raw]
Subject: Re: [PATCH] cxl: Fix refcount leak in cxl_calc_capp_routing

On Mon, 2022-11-14 at 12:42 +0000, Christophe Leroy wrote:
> Should this be applied by Bjorn as most recent changes to that file ?

We usually take cxl patches through powerpc, though sometimes Greg
picks them up through char-misc.

--
Andrew Donnellan OzLabs, ADL Canberra
[email protected] IBM Australia Limited

2022-11-30 11:09:47

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH] cxl: Fix refcount leak in cxl_calc_capp_routing

On Sun, 5 Jun 2022 10:00:38 +0400, Miaoqian Lin wrote:
> of_get_next_parent() returns a node pointer with refcount incremented,
> we should use of_node_put() on it when not need anymore.
> This function only calls of_node_put() in normal path,
> missing it in the error path.
> Add missing of_node_put() to avoid refcount leak.
>
>
> [...]

Applied to powerpc/next.

[1/1] cxl: Fix refcount leak in cxl_calc_capp_routing
https://git.kernel.org/powerpc/c/1d09697ff22908ae487fc8c4fbde1811732be523

cheers