linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: ishraq.i.ashraf@gmail.com
Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
	insafonov@gmail.com, goudapatilk@gmail.com,
	linux-kernel@vger.kernel.org, himanshujha199640@gmail.com
Subject: Re: [PATCH v2] staging: rtl8188eu: Fix private WEXT IOCTL calls
Date: Sat, 25 Nov 2017 07:55:15 +0300	[thread overview]
Message-ID: <20171125045515.xsi35e4zddunumve@mwanda> (raw)
In-Reply-To: <1511573376-16102-1-git-send-email-ishraq.i.ashraf@gmail.com>

On Sat, Nov 25, 2017 at 02:29:36AM +0100, ishraq.i.ashraf@gmail.com wrote:
> +
> +	ret = 0;
> +

Sorry, I wasn't clear before.  When I said don't initialize "ret" to
zero, I just meant that in that specific case we initialized "ret" and
then immediately reassigned it with:

	ret = some_function();
	if (ret)
		return ret;

In this case it's fine to set "ret = 0" at the start so that we don't
have to do it later.

> +	if (copy_to_user(wrqu->data.pointer, param, wrqu->data.length))
> +		ret = -EFAULT;
> +
> +	if (pwep)
> +		goto err_free_pwep_param;
> +
> +	err_free_param:
> +		kfree(param);
> +		return ret;
> +
> +	err_free_pwep_param:
> +		kfree(pwep);
> +		kfree(param);
> +		return ret;
> +}

Hm...  I said before that it's better to keep the error paths and
success path separate but in this case it's probabaly simpler to merge
them.

This one could look like this:

	if (copy_to_user(wrqu->data.pointer, param, wrqu->data.length))
		ret = -EFAULT;

free_pwep:
	kfree(pwep);
free_param:
	kfree(param);
	return ret;

There is no need for the if (pwep) conditions, because kfree() can
take a NULL pointer.  Some people would just use one label but I hate
that.  It looks like this:

free:
	kfree(pwep);
	kfree(param);
	return ret;

The reason, I hate it is because I don't like freeing things which have
not been allocated yet.  If you do it the normal kernel way then you
just have to keep track of the most recently allocated thing.

regards,
dan carpenter

  reply	other threads:[~2017-11-25  4:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-23  1:29 [PATCH] staging: rtl8188eu: Fix private WEXT IOCTL calls ishraq.i.ashraf
2017-11-23 13:24 ` Dan Carpenter
2017-11-25  0:52 ` [PATCH 2/2] " ishraq.i.ashraf
2017-11-25  4:40   ` Dan Carpenter
2017-11-25 18:12     ` Ishraq Ibne Ashraf
2017-11-26  0:45     ` Ishraq Ibne Ashraf
2017-11-27 11:33       ` Johannes Berg
2017-11-25  1:29 ` [PATCH v2] " ishraq.i.ashraf
2017-11-25  4:55   ` Dan Carpenter [this message]
2017-11-25 18:29 ` [PATCH v3] " ishraq.i.ashraf
2017-11-25 21:25   ` Dan Carpenter
2017-11-27 11:24   ` Johannes Berg
2017-11-28  8:00   ` [PATCH] staging: rtl8188eu: fix kzalloc-simple.cocci warnings kbuild test robot
2017-11-28  8:00   ` [PATCH v3] staging: rtl8188eu: Fix private WEXT IOCTL calls kbuild test robot
2017-12-04 15:20   ` kbuild test robot
2017-11-26 20:45 ` [PATCH] " kbuild test robot
2017-11-26 23:20 ` kbuild test robot

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=20171125045515.xsi35e4zddunumve@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=goudapatilk@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=himanshujha199640@gmail.com \
    --cc=insafonov@gmail.com \
    --cc=ishraq.i.ashraf@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).