All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] powerpc: kernel: fix refcount leak in format_show()
@ 2022-03-02  2:19 Hangyu Hua
  2022-03-07  2:52 ` Hangyu Hua
  2022-03-12 10:29 ` Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Hangyu Hua @ 2022-03-02  2:19 UTC (permalink / raw)
  To: mpe, benh, paulus, tyreld; +Cc: linuxppc-dev, linux-kernel, Hangyu Hua

Refcount leak will happen when format_show returns failure in multiple
cases. Unified management of of_node_put can fix this problem.

Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---

v2: 
1. change the title and description information. 
2. fix all possible refcount leak.

 arch/powerpc/kernel/secvar-sysfs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c
index a0a78aba2083..1ee4640a2641 100644
--- a/arch/powerpc/kernel/secvar-sysfs.c
+++ b/arch/powerpc/kernel/secvar-sysfs.c
@@ -26,15 +26,18 @@ static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr,
 	const char *format;
 
 	node = of_find_compatible_node(NULL, NULL, "ibm,secvar-backend");
-	if (!of_device_is_available(node))
-		return -ENODEV;
+	if (!of_device_is_available(node)) {
+		rc = -ENODEV;
+		goto out;
+	}
 
 	rc = of_property_read_string(node, "format", &format);
 	if (rc)
-		return rc;
+		goto out;
 
 	rc = sprintf(buf, "%s\n", format);
 
+out:
 	of_node_put(node);
 
 	return rc;
-- 
2.25.1


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

* Re: [PATCH v2] powerpc: kernel: fix refcount leak in format_show()
  2022-03-02  2:19 [PATCH v2] powerpc: kernel: fix refcount leak in format_show() Hangyu Hua
@ 2022-03-07  2:52 ` Hangyu Hua
  2022-03-12 10:29 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Hangyu Hua @ 2022-03-07  2:52 UTC (permalink / raw)
  To: mpe, benh, paulus, tyreld; +Cc: linuxppc-dev, linux-kernel

Any further suggestions for this patch? guys.

Thanks.

On 2022/3/2 10:19, Hangyu Hua wrote:
> Refcount leak will happen when format_show returns failure in multiple
> cases. Unified management of of_node_put can fix this problem.
> 
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---
> 
> v2:
> 1. change the title and description information.
> 2. fix all possible refcount leak.
> 
>   arch/powerpc/kernel/secvar-sysfs.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c
> index a0a78aba2083..1ee4640a2641 100644
> --- a/arch/powerpc/kernel/secvar-sysfs.c
> +++ b/arch/powerpc/kernel/secvar-sysfs.c
> @@ -26,15 +26,18 @@ static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr,
>   	const char *format;
>   
>   	node = of_find_compatible_node(NULL, NULL, "ibm,secvar-backend");
> -	if (!of_device_is_available(node))
> -		return -ENODEV;
> +	if (!of_device_is_available(node)) {
> +		rc = -ENODEV;
> +		goto out;
> +	}
>   
>   	rc = of_property_read_string(node, "format", &format);
>   	if (rc)
> -		return rc;
> +		goto out;
>   
>   	rc = sprintf(buf, "%s\n", format);
>   
> +out:
>   	of_node_put(node);
>   
>   	return rc;

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

* Re: [PATCH v2] powerpc: kernel: fix refcount leak in format_show()
  2022-03-02  2:19 [PATCH v2] powerpc: kernel: fix refcount leak in format_show() Hangyu Hua
  2022-03-07  2:52 ` Hangyu Hua
@ 2022-03-12 10:29 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2022-03-12 10:29 UTC (permalink / raw)
  To: mpe, benh, tyreld, Hangyu Hua, paulus; +Cc: linuxppc-dev, linux-kernel

On Wed, 2 Mar 2022 10:19:59 +0800, Hangyu Hua wrote:
> Refcount leak will happen when format_show returns failure in multiple
> cases. Unified management of of_node_put can fix this problem.
> 
> 

Applied to powerpc/next.

[1/1] powerpc: kernel: fix refcount leak in format_show()
      https://git.kernel.org/powerpc/c/d601fd24e6964967f115f036a840f4f28488f63f

cheers

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

end of thread, other threads:[~2022-03-12 10:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02  2:19 [PATCH v2] powerpc: kernel: fix refcount leak in format_show() Hangyu Hua
2022-03-07  2:52 ` Hangyu Hua
2022-03-12 10:29 ` Michael Ellerman

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.