All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Nishka Dasgupta <nishkadg.linux@gmail.com>
Cc: matthias.bgg@gmail.com, linux-mediatek@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-input@vger.kernel.org
Subject: Re: [PATCH] input: keyboard: mtk-pmic-keys: Add of_node_put() before return
Date: Thu, 11 Jul 2019 23:50:17 -0700	[thread overview]
Message-ID: <20190712065017.GF150689@dtor-ws> (raw)
In-Reply-To: <20190709180019.14339-1-nishkadg.linux@gmail.com>

On Tue, Jul 09, 2019 at 11:30:19PM +0530, Nishka Dasgupta wrote:
> Each iteration of for_each_child_of_node puts the previous
> node, but in the case of a return from the middle of the loop, there is
> no put, thus causing a memory leak. Hence add an of_node_put before the
> return in three places.
> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>

Applied, thank you.

> ---
>  drivers/input/keyboard/mtk-pmic-keys.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> index 746ff06eaf8d..62391d6c7da6 100644
> --- a/drivers/input/keyboard/mtk-pmic-keys.c
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -277,8 +277,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
>  		keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];
>  
>  		keys->keys[index].irq = platform_get_irq(pdev, index);
> -		if (keys->keys[index].irq < 0)
> +		if (keys->keys[index].irq < 0) {
> +			of_node_put(child);
>  			return keys->keys[index].irq;
> +		}
>  
>  		error = of_property_read_u32(child,
>  			"linux,keycodes", &keys->keys[index].keycode);
> @@ -286,6 +288,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
>  			dev_err(keys->dev,
>  				"failed to read key:%d linux,keycode property: %d\n",
>  				index, error);
> +			of_node_put(child);
>  			return error;
>  		}
>  
> @@ -293,8 +296,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
>  			keys->keys[index].wakeup = true;
>  
>  		error = mtk_pmic_key_setup(keys, &keys->keys[index]);
> -		if (error)
> +		if (error) {
> +			of_node_put(child);
>  			return error;
> +		}
>  
>  		index++;
>  	}
> -- 
> 2.19.1
> 

-- 
Dmitry

WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Nishka Dasgupta <nishkadg.linux@gmail.com>
Cc: matthias.bgg@gmail.com, linux-mediatek@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-input@vger.kernel.org
Subject: Re: [PATCH] input: keyboard: mtk-pmic-keys: Add of_node_put() before return
Date: Thu, 11 Jul 2019 23:50:17 -0700	[thread overview]
Message-ID: <20190712065017.GF150689@dtor-ws> (raw)
In-Reply-To: <20190709180019.14339-1-nishkadg.linux@gmail.com>

On Tue, Jul 09, 2019 at 11:30:19PM +0530, Nishka Dasgupta wrote:
> Each iteration of for_each_child_of_node puts the previous
> node, but in the case of a return from the middle of the loop, there is
> no put, thus causing a memory leak. Hence add an of_node_put before the
> return in three places.
> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>

Applied, thank you.

> ---
>  drivers/input/keyboard/mtk-pmic-keys.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> index 746ff06eaf8d..62391d6c7da6 100644
> --- a/drivers/input/keyboard/mtk-pmic-keys.c
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -277,8 +277,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
>  		keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];
>  
>  		keys->keys[index].irq = platform_get_irq(pdev, index);
> -		if (keys->keys[index].irq < 0)
> +		if (keys->keys[index].irq < 0) {
> +			of_node_put(child);
>  			return keys->keys[index].irq;
> +		}
>  
>  		error = of_property_read_u32(child,
>  			"linux,keycodes", &keys->keys[index].keycode);
> @@ -286,6 +288,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
>  			dev_err(keys->dev,
>  				"failed to read key:%d linux,keycode property: %d\n",
>  				index, error);
> +			of_node_put(child);
>  			return error;
>  		}
>  
> @@ -293,8 +296,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
>  			keys->keys[index].wakeup = true;
>  
>  		error = mtk_pmic_key_setup(keys, &keys->keys[index]);
> -		if (error)
> +		if (error) {
> +			of_node_put(child);
>  			return error;
> +		}
>  
>  		index++;
>  	}
> -- 
> 2.19.1
> 

-- 
Dmitry

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-07-12  6:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-09 18:00 [PATCH] input: keyboard: mtk-pmic-keys: Add of_node_put() before return Nishka Dasgupta
2019-07-09 18:00 ` Nishka Dasgupta
2019-07-12  6:50 ` Dmitry Torokhov [this message]
2019-07-12  6:50   ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190712065017.GF150689@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nishkadg.linux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.