mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Larry Finger <Larry.Finger@lwfinger.net>
To: Nicholas Krause <xerofoify@gmail.com>, rmk+kernel@arm.linux.org.uk
Cc: dbaryshkov@gmail.com, linux-pcmcia@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] pcmcia:Fix memory leaks in the function, sa11xx_drv_pcmcia_probe
Date: Wed, 25 Mar 2015 01:11:48 -0500	[thread overview]
Message-ID: <551251A4.1030501@lwfinger.net> (raw)
In-Reply-To: <1427257453-22159-1-git-send-email-xerofoify@gmail.com>

On 03/24/2015 11:24 PM, Nicholas Krause wrote:
> Fixes memory leaks in the function,sa11xx_drv_pcmcia_probe for
> when either clk_get returns a error value  or when we cannot allocate
> memory  with the pointer sinfo to memory required for this function
> to continue and return successfully. Further more this was caught by
> running coccinelle on the lastet kernel tree.
>
> Signed-off-by: Nicholas Krause <xerofoify@gmail.com>
> ---
>   drivers/pcmcia/sa11xx_base.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pcmcia/sa11xx_base.c b/drivers/pcmcia/sa11xx_base.c
> index cf6de2c..a95ce73 100644
> --- a/drivers/pcmcia/sa11xx_base.c
> +++ b/drivers/pcmcia/sa11xx_base.c
> @@ -223,14 +223,19 @@ int sa11xx_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops,
>   	struct clk *clk;
>
>   	clk = clk_get(dev, NULL);
> -	if (IS_ERR(clk))
> +	if (IS_ERR(clk)) {
> +		clk_put(clk);
>   		return PTR_ERR(clk);
> +	}

If the clk_get() failed, then there is no need to use a clk_put(). In addition, 
clk contains an error code, not a valid pointer. This change would crash the 
system every time clk_get() failed.

>
>   	sa11xx_drv_pcmcia_ops(ops);
>
>   	sinfo = kzalloc(SKT_DEV_INFO_SIZE(nr), GFP_KERNEL);
> -	if (!sinfo)
> +	if (!sinfo) {
> +		clk_put(clk);
> +		kfree(sinfo);
>   		return -ENOMEM;

If the memory allocation failed, there is nothing to free. That kfree() call is 
not needed; however, the clk_put() is needed here.

NACK.

Larry


> +	}
>
>   	sinfo->nskt = nr;
>   	sinfo->clk = clk;
>


           reply	other threads:[~2015-03-25  6:11 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1427257453-22159-1-git-send-email-xerofoify@gmail.com>]

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=551251A4.1030501@lwfinger.net \
    --to=larry.finger@lwfinger.net \
    --cc=dbaryshkov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pcmcia@lists.infradead.org \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=xerofoify@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®