diff mbox series

[v2] powerpc: kernel: fix refcount leak in format_show()

Message ID 20220302021959.10959-1-hbh25y@gmail.com (mailing list archive)
State Accepted
Headers show
Series [v2] powerpc: kernel: fix refcount leak in format_show() | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 7 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 24 jobs.

Commit Message

Hangyu Hua March 2, 2022, 2:19 a.m. UTC
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(-)

Comments

Hangyu Hua March 7, 2022, 2:52 a.m. UTC | #1
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;
Michael Ellerman March 12, 2022, 10:29 a.m. UTC | #2
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
diff mbox series

Patch

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;