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>
Cc: devel@driverdev.osuosl.org, y.k.oh@samsung.com,
	gregkh@linuxfoundation.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org, julia.lawall@lip6.fr,
	forest@alittletooquiet.net, santhameena13@gmail.com
Subject: Re: [PATCH v3] staging: vt6655: check for memory allocation failures
Date: Fri, 30 Mar 2018 11:50:08 +0800	[thread overview]
Message-ID: <b66f4737-f66b-7104-ddec-2da292d1c5ef@gmail.com> (raw)
In-Reply-To: <20180330033933.GA26489@ubuntu>



On 2018/3/30 11:39, Ji-Hun Kim wrote:
> On Fri, Mar 30, 2018 at 11:15:03AM +0800, Jia-Ju Bai wrote:
>>
>> 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
>>
>>
> But, those freeing function are already placed in the each device_init
> functions for allocation fail like below.

I think it is okay.
I suppose that, for each device_init function, you only free the 
resources allocated in this function, and do not handle the resources in 
other functions.

> @@ -550,20 +554,29 @@ static void device_init_rd0_ring(struct vnt_private *priv)
> +       return 0;
> +error:
> +       device_free_rd0_ring(priv);
> +       return ret;

This code is needed to free the resources allocated in this function.


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:50 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
2018-03-30  3:39     ` Ji-Hun Kim
2018-03-30  3:50       ` Jia-Ju Bai [this message]
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=b66f4737-f66b-7104-ddec-2da292d1c5ef@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

all inboxes | Powered by JetHome®