linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] powerpc/sparse: fix possible object reference leak
@ 2019-03-22  3:05 Wen Yang
  2019-03-22  3:05 ` [PATCH 2/5] powerpc/83xx: " Wen Yang
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Wen Yang @ 2019-03-22  3:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: wang.yi59, Wen Yang, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, linuxppc-dev

The call to of_find_node_by_path returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./arch/powerpc/platforms/pseries/pseries_energy.c:101:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 46, but without a corresponding object release within this function.
./arch/powerpc/platforms/pseries/pseries_energy.c:172:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 111, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
---
 arch/powerpc/platforms/pseries/pseries_energy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/pseries_energy.c b/arch/powerpc/platforms/pseries/pseries_energy.c
index 6ed2212..e3913e4 100644
--- a/arch/powerpc/platforms/pseries/pseries_energy.c
+++ b/arch/powerpc/platforms/pseries/pseries_energy.c
@@ -69,7 +69,7 @@ static u32 cpu_to_drc_index(int cpu)
 
 			of_read_drc_info_cell(&info, &value, &drc);
 			if (strncmp(drc.drc_type, "CPU", 3))
-				goto err;
+				goto err_of_node_put;
 
 			if (thread_index < drc.last_drc_index)
 				break;
@@ -131,7 +131,7 @@ static int drc_index_to_cpu(u32 drc_index)
 
 			of_read_drc_info_cell(&info, &value, &drc);
 			if (strncmp(drc.drc_type, "CPU", 3))
-				goto err;
+				goto err_of_node_put;
 
 			if (drc_index > drc.last_drc_index) {
 				cpu += drc.num_sequential_elems;
-- 
2.9.5


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

* [PATCH 2/5] powerpc/83xx: fix possible object reference leak
  2019-03-22  3:05 [PATCH 1/5] powerpc/sparse: fix possible object reference leak Wen Yang
@ 2019-03-22  3:05 ` Wen Yang
  2022-03-27  7:09   ` Christophe Leroy
  2019-03-22  3:05 ` [PATCH 3/5] powerpc/powernv: " Wen Yang
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Wen Yang @ 2019-03-22  3:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: wang.yi59, Wen Yang, Scott Wood, Kumar Gala,
	Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	linuxppc-dev

The call to of_find_node_by_name returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./arch/powerpc/platforms/83xx/km83xx.c:68:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 59, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Scott Wood <oss@buserror.net>
Cc: Kumar Gala <galak@kernel.crashing.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
---
 arch/powerpc/platforms/83xx/km83xx.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/platforms/83xx/km83xx.c b/arch/powerpc/platforms/83xx/km83xx.c
index d8642a4..11eea7c 100644
--- a/arch/powerpc/platforms/83xx/km83xx.c
+++ b/arch/powerpc/platforms/83xx/km83xx.c
@@ -65,6 +65,7 @@ static void quirk_mpc8360e_qe_enet10(void)
 	ret = of_address_to_resource(np_par, 0, &res);
 	if (ret) {
 		pr_warn("%s couldn;t map par_io registers\n", __func__);
+		of_node_put(np_par);
 		return;
 	}
 
-- 
2.9.5


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

* [PATCH 3/5] powerpc/powernv: fix possible object reference leak
  2019-03-22  3:05 [PATCH 1/5] powerpc/sparse: fix possible object reference leak Wen Yang
  2019-03-22  3:05 ` [PATCH 2/5] powerpc/83xx: " Wen Yang
@ 2019-03-22  3:05 ` Wen Yang
  2019-03-22  3:05 ` [PATCH 4/5] powerpc/embedded6xx: " Wen Yang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Wen Yang @ 2019-03-22  3:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: wang.yi59, Wen Yang, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, Nicholas Piggin, Mike Rapoport, Andrew Morton,
	Mahesh Salgaonkar, Haren Myneni, linuxppc-dev

The call to of_find_node_by_path returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./arch/powerpc/platforms/powernv/opal.c:741:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 733, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Cc: Haren Myneni <haren@linux.vnet.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
---
 arch/powerpc/platforms/powernv/opal.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index 2b0eca1..d7736a5 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -738,6 +738,7 @@ static void opal_export_attrs(void)
 	kobj = kobject_create_and_add("exports", opal_kobj);
 	if (!kobj) {
 		pr_warn("kobject_create_and_add() of exports failed\n");
+		of_node_put(np);
 		return;
 	}
 
-- 
2.9.5


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

* [PATCH 4/5] powerpc/embedded6xx: fix possible object reference leak
  2019-03-22  3:05 [PATCH 1/5] powerpc/sparse: fix possible object reference leak Wen Yang
  2019-03-22  3:05 ` [PATCH 2/5] powerpc/83xx: " Wen Yang
  2019-03-22  3:05 ` [PATCH 3/5] powerpc/powernv: " Wen Yang
@ 2019-03-22  3:05 ` Wen Yang
  2019-03-22  3:05 ` [PATCH 5/5] powerpc/8xx: " Wen Yang
  2019-04-05  8:50 ` [1/5] powerpc/sparse: " Markus Elfring
  4 siblings, 0 replies; 8+ messages in thread
From: Wen Yang @ 2019-03-22  3:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: wang.yi59, Wen Yang, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, linuxppc-dev

The call to of_find_compatible_node returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./arch/powerpc/platforms/embedded6xx/mvme5100.c:89:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 80, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
---
 arch/powerpc/platforms/embedded6xx/mvme5100.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/platforms/embedded6xx/mvme5100.c b/arch/powerpc/platforms/embedded6xx/mvme5100.c
index 273dfa3..660654f4 100644
--- a/arch/powerpc/platforms/embedded6xx/mvme5100.c
+++ b/arch/powerpc/platforms/embedded6xx/mvme5100.c
@@ -86,6 +86,7 @@ static void __init mvme5100_pic_init(void)
 	cirq = irq_of_parse_and_map(cp, 0);
 	if (!cirq) {
 		pr_warn("mvme5100_pic_init: no cascade interrupt?\n");
+		of_node_put(cp);
 		return;
 	}
 
-- 
2.9.5


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

* [PATCH 5/5] powerpc/8xx: fix possible object reference leak
  2019-03-22  3:05 [PATCH 1/5] powerpc/sparse: fix possible object reference leak Wen Yang
                   ` (2 preceding siblings ...)
  2019-03-22  3:05 ` [PATCH 4/5] powerpc/embedded6xx: " Wen Yang
@ 2019-03-22  3:05 ` Wen Yang
  2019-03-22  7:09   ` Christophe Leroy
  2019-04-05  8:50 ` [1/5] powerpc/sparse: " Markus Elfring
  4 siblings, 1 reply; 8+ messages in thread
From: Wen Yang @ 2019-03-22  3:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: wang.yi59, Wen Yang, Vitaly Bordug, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, linuxppc-dev

The call to of_find_compatible_node returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.
irq_domain_add_linear also calls of_node_get to increase refcount,
so irq_domain will not be affected when it is released.

Detected by coccinelle with the following warnings:
./arch/powerpc/platforms/8xx/pic.c:158:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 136, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Vitaly Bordug <vitb@kernel.crashing.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
---
 arch/powerpc/platforms/8xx/pic.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/platforms/8xx/pic.c b/arch/powerpc/platforms/8xx/pic.c
index 8d5a25d..13d880b 100644
--- a/arch/powerpc/platforms/8xx/pic.c
+++ b/arch/powerpc/platforms/8xx/pic.c
@@ -155,6 +155,7 @@ int mpc8xx_pic_init(void)
 		ret = -ENOMEM;
 		goto out;
 	}
+	of_node_put(np);
 	return 0;
 
 out:
-- 
2.9.5


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

* Re: [PATCH 5/5] powerpc/8xx: fix possible object reference leak
  2019-03-22  3:05 ` [PATCH 5/5] powerpc/8xx: " Wen Yang
@ 2019-03-22  7:09   ` Christophe Leroy
  0 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2019-03-22  7:09 UTC (permalink / raw)
  To: Wen Yang, linux-kernel; +Cc: wang.yi59, Paul Mackerras, linuxppc-dev



On 03/22/2019 03:05 AM, Wen Yang wrote:
> The call to of_find_compatible_node returns a node pointer with refcount
> incremented thus it must be explicitly decremented after the last
> usage.
> irq_domain_add_linear also calls of_node_get to increase refcount,
> so irq_domain will not be affected when it is released.


Should you have a:

Fixes: a8db8cf0d894 ("irq_domain: Replace irq_alloc_host() with 
revmap-specific initializers")

If not, it means your change is in contradiction with commit 
b1725c9319aa ("[POWERPC] arch/powerpc/sysdev: Add missing of_node_put")

> 
> Detected by coccinelle with the following warnings:
> ./arch/powerpc/platforms/8xx/pic.c:158:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 136, but without a corresponding object release within this function.
> 
> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
> Cc: Vitaly Bordug <vitb@kernel.crashing.org>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-kernel@vger.kernel.org
> ---
>   arch/powerpc/platforms/8xx/pic.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/arch/powerpc/platforms/8xx/pic.c b/arch/powerpc/platforms/8xx/pic.c
> index 8d5a25d..13d880b 100644
> --- a/arch/powerpc/platforms/8xx/pic.c
> +++ b/arch/powerpc/platforms/8xx/pic.c
> @@ -155,6 +155,7 @@ int mpc8xx_pic_init(void)
>   		ret = -ENOMEM;
>   		goto out;
>   	}
> +	of_node_put(np);
>   	return 0;
>   
>   out:
> 

I guess it would be better as follows:

--- a/arch/powerpc/platforms/8xx/pic.c
+++ b/arch/powerpc/platforms/8xx/pic.c
@@ -153,9 +153,7 @@ int mpc8xx_pic_init(void)
         if (mpc8xx_pic_host == NULL) {
                 printk(KERN_ERR "MPC8xx PIC: failed to allocate irq 
host!\n");
                 ret = -ENOMEM;
-               goto out;
         }
-       return 0;

  out:
         of_node_put(np);



Christophe

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

* Re: [1/5] powerpc/sparse: fix possible object reference leak
  2019-03-22  3:05 [PATCH 1/5] powerpc/sparse: fix possible object reference leak Wen Yang
                   ` (3 preceding siblings ...)
  2019-03-22  3:05 ` [PATCH 5/5] powerpc/8xx: " Wen Yang
@ 2019-04-05  8:50 ` Markus Elfring
  4 siblings, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2019-04-05  8:50 UTC (permalink / raw)
  To: Wen Yang, linuxppc-dev, kernel-janitors
  Cc: linux-kernel, Benjamin Herrenschmidt, Michael Ellerman,
	Paul Mackerras, Yi Wang

> @@ -131,7 +131,7 @@  static int drc_index_to_cpu(u32 drc_index)
>
>  			of_read_drc_info_cell(&info, &value, &drc);
>  			if (strncmp(drc.drc_type, "CPU", 3))
> -				goto err;
> +				goto err_of_node_put;
>
>  			if (drc_index > drc.last_drc_index) {

Can the jump label “put_node” be nicer here?

Regards,
Markus

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

* Re: [PATCH 2/5] powerpc/83xx: fix possible object reference leak
  2019-03-22  3:05 ` [PATCH 2/5] powerpc/83xx: " Wen Yang
@ 2022-03-27  7:09   ` Christophe Leroy
  0 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2022-03-27  7:09 UTC (permalink / raw)
  To: Wen Yang, linux-kernel
  Cc: wang.yi59, Scott Wood, Paul Mackerras, linuxppc-dev



Le 22/03/2019 à 04:05, Wen Yang a écrit :
> The call to of_find_node_by_name returns a node pointer with refcount
> incremented thus it must be explicitly decremented after the last
> usage.
> 
> Detected by coccinelle with the following warnings:
> ./arch/powerpc/platforms/83xx/km83xx.c:68:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 59, but without a corresponding object release within this function.

This was fixed by 
https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id=88654d5b4476

> 
> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
> Cc: Scott Wood <oss@buserror.net>
> Cc: Kumar Gala <galak@kernel.crashing.org>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-kernel@vger.kernel.org
> ---
>   arch/powerpc/platforms/83xx/km83xx.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/arch/powerpc/platforms/83xx/km83xx.c b/arch/powerpc/platforms/83xx/km83xx.c
> index d8642a4..11eea7c 100644
> --- a/arch/powerpc/platforms/83xx/km83xx.c
> +++ b/arch/powerpc/platforms/83xx/km83xx.c
> @@ -65,6 +65,7 @@ static void quirk_mpc8360e_qe_enet10(void)
>   	ret = of_address_to_resource(np_par, 0, &res);
>   	if (ret) {
>   		pr_warn("%s couldn;t map par_io registers\n", __func__);
> +		of_node_put(np_par);
>   		return;
>   	}
>   

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

end of thread, other threads:[~2022-03-27  7:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22  3:05 [PATCH 1/5] powerpc/sparse: fix possible object reference leak Wen Yang
2019-03-22  3:05 ` [PATCH 2/5] powerpc/83xx: " Wen Yang
2022-03-27  7:09   ` Christophe Leroy
2019-03-22  3:05 ` [PATCH 3/5] powerpc/powernv: " Wen Yang
2019-03-22  3:05 ` [PATCH 4/5] powerpc/embedded6xx: " Wen Yang
2019-03-22  3:05 ` [PATCH 5/5] powerpc/8xx: " Wen Yang
2019-03-22  7:09   ` Christophe Leroy
2019-04-05  8:50 ` [1/5] powerpc/sparse: " Markus Elfring

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).