diff mbox series

x86, olpc: Avoid leak OF node on error

Message ID 20220523111253.3114-1-chi.minghao@zte.com.cn (mailing list archive)
State Rejected, archived
Headers show
Series x86, olpc: Avoid leak OF node on error | expand

Commit Message

CGEL May 23, 2022, 11:12 a.m. UTC
From: Minghao Chi <chi.minghao@zte.com.cn>

The OF node should be put before returning error in xo1_rtc_init(),
otherwise node's refcount will be leaked.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
---
 arch/x86/platform/olpc/olpc-xo1-rtc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Hans de Goede May 23, 2022, 11:53 a.m. UTC | #1
Hi,

On 5/23/22 13:12, cgel.zte@gmail.com wrote:
> From: Minghao Chi <chi.minghao@zte.com.cn>
> 
> The OF node should be put before returning error in xo1_rtc_init(),
> otherwise node's refcount will be leaked.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> ---
>  arch/x86/platform/olpc/olpc-xo1-rtc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/platform/olpc/olpc-xo1-rtc.c b/arch/x86/platform/olpc/olpc-xo1-rtc.c
> index 57f210cda761..dc5ac56cd9dd 100644
> --- a/arch/x86/platform/olpc/olpc-xo1-rtc.c
> +++ b/arch/x86/platform/olpc/olpc-xo1-rtc.c
> @@ -59,9 +59,9 @@ static int __init xo1_rtc_init(void)
>  	struct device_node *node;
>  
>  	node = of_find_compatible_node(NULL, NULL, "olpc,xo1-rtc");
> +	of_node_put(node);
>  	if (!node)
>  		return 0;
> -	of_node_put(node);
>  
>  	pr_info("olpc-xo1-rtc: Initializing OLPC XO-1 RTC\n");
>  	rdmsrl(MSR_RTC_DOMA_OFFSET, rtc_info.rtc_day_alarm);

of_node_put on a NULL node is a no-op, so this patch
does not make any functional difference and it makes the
code harder to read.

nack.

Regards,

Hans
Johan Hovold May 23, 2022, 11:53 a.m. UTC | #2
On Mon, May 23, 2022 at 11:12:53AM +0000, cgel.zte@gmail.com wrote:
> From: Minghao Chi <chi.minghao@zte.com.cn>
> 
> The OF node should be put before returning error in xo1_rtc_init(),
> otherwise node's refcount will be leaked.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> ---
>  arch/x86/platform/olpc/olpc-xo1-rtc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/platform/olpc/olpc-xo1-rtc.c b/arch/x86/platform/olpc/olpc-xo1-rtc.c
> index 57f210cda761..dc5ac56cd9dd 100644
> --- a/arch/x86/platform/olpc/olpc-xo1-rtc.c
> +++ b/arch/x86/platform/olpc/olpc-xo1-rtc.c
> @@ -59,9 +59,9 @@ static int __init xo1_rtc_init(void)
>  	struct device_node *node;
>  
>  	node = of_find_compatible_node(NULL, NULL, "olpc,xo1-rtc");
> +	of_node_put(node);
>  	if (!node)
>  		return 0;
> -	of_node_put(node);

Is this a joke? Don't you guys even try to understand the code your
"robot" tells you to change?

Please don't send any more patches until you've figured out how you
messed up here.

>  	pr_info("olpc-xo1-rtc: Initializing OLPC XO-1 RTC\n");
>  	rdmsrl(MSR_RTC_DOMA_OFFSET, rtc_info.rtc_day_alarm);

Johan
diff mbox series

Patch

diff --git a/arch/x86/platform/olpc/olpc-xo1-rtc.c b/arch/x86/platform/olpc/olpc-xo1-rtc.c
index 57f210cda761..dc5ac56cd9dd 100644
--- a/arch/x86/platform/olpc/olpc-xo1-rtc.c
+++ b/arch/x86/platform/olpc/olpc-xo1-rtc.c
@@ -59,9 +59,9 @@  static int __init xo1_rtc_init(void)
 	struct device_node *node;
 
 	node = of_find_compatible_node(NULL, NULL, "olpc,xo1-rtc");
+	of_node_put(node);
 	if (!node)
 		return 0;
-	of_node_put(node);
 
 	pr_info("olpc-xo1-rtc: Initializing OLPC XO-1 RTC\n");
 	rdmsrl(MSR_RTC_DOMA_OFFSET, rtc_info.rtc_day_alarm);