mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: Ji-Hun Kim <ji_hun.kim@samsung.com>,
	gregkh@linuxfoundation.org, forest@alittletooquiet.net
Cc: devel@driverdev.osuosl.org, y.k.oh@samsung.com,
	kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
	julia.lawall@lip6.fr, santhameena13@gmail.com
Subject: Re: [PATCH v3] staging: vt6655: check for memory allocation failures
Date: Fri, 30 Mar 2018 11:15:03 +0800	[thread overview]
Message-ID: <be23acda-38c0-dce3-9c79-8672113f6960@gmail.com> (raw)
In-Reply-To: <1522377844-23591-1-git-send-email-ji_hun.kim@samsung.com>



On 2018/3/30 10:44, Ji-Hun Kim wrote:
> @@ -1165,10 +1205,18 @@ static int vnt_start(struct ieee80211_hw *hw)
>   	}
>   
>   	dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
> -	device_init_rd0_ring(priv);
> -	device_init_rd1_ring(priv);
> -	device_init_td0_ring(priv);
> -	device_init_td1_ring(priv);
> +	ret = device_init_rd0_ring(priv);
> +	if (ret)
> +		goto error;
> +	ret = device_init_rd1_ring(priv);
> +	if (ret)
> +		goto error;
> +	ret = device_init_td0_ring(priv);
> +	if (ret)
> +		goto error;
> +	ret = device_init_td1_ring(priv);
> +	if (ret)
> +		goto error;
>   
>   	device_init_registers(priv);
>   
> @@ -1178,6 +1226,8 @@ static int vnt_start(struct ieee80211_hw *hw)
>   	ieee80211_wake_queues(hw);
>   
>   	return 0;
> +error:
> +	return ret;
>   }

This code will lead to memory leaks when device_init_rd1_ring() fails, 
because the memory allocated by device_init_rd0_ring() is not freed.

I think this one will be better:
     ret = device_init_rd0_ring(priv);
     if (ret)
         goto error_init_rd0_ring;
     ret = device_init_rd1_ring(priv);
     if (ret)
         goto error_init_rd1_ring;
     ret = device_init_td0_ring(priv);
     if (ret)
         goto error_init_td0_ring;
     ret = device_init_td1_ring(priv);
     if (ret)
         goto error_init_td1_ring;
     ......
error_init_td1_ring:
     device_free_td0_ring(priv);
error_init_td0_ring:
     device_free_rd1_ring(priv);
error_init_rd1_ring:
     device_free_rd0_ring(priv);
error_init_rd0_ring:
     return ret;


Best wishes,
Jia-Ju Bai
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2018-03-30  3:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180330024416epcas2p2f566f43a8f5af8b4ebc17659e3cf0ecf@epcas2p2.samsung.com>
2018-03-30  2:44 ` Ji-Hun Kim
2018-03-30  3:15   ` Jia-Ju Bai [this message]
2018-03-30  3:39     ` Ji-Hun Kim
2018-03-30  3:50       ` Jia-Ju Bai
2018-03-30  3:50     ` Ji-Hun Kim
2018-04-03 10:40   ` Dan Carpenter
2018-04-04  7:24     ` Ji-Hun Kim
2018-04-04  9:53       ` Dan Carpenter

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=be23acda-38c0-dce3-9c79-8672113f6960@gmail.com \
    --to=baijiaju1990@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=forest@alittletooquiet.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=ji_hun.kim@samsung.com \
    --cc=julia.lawall@lip6.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=santhameena13@gmail.com \
    --cc=y.k.oh@samsung.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

Powered by JetHome