From: Chandra Gorentla <csgorentla@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: gregkh@linuxfoundation.org, rachel.kim@atmel.com,
devel@driverdev.osuosl.org, chris.park@atmel.com,
linux-wireless@vger.kernel.org, johnny.kim@atmel.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] drivers: staging: wilc1000: Check for errors before kfree
Date: Sat, 3 Oct 2015 07:41:13 +0530 [thread overview]
Message-ID: <20151003021112.GA9115@gcs-HP-Notebook> (raw)
In-Reply-To: <20151002133911.GP7289@mwanda>
On Fri, Oct 02, 2015 at 04:39:11PM +0300, Dan Carpenter wrote:
> On Fri, Oct 02, 2015 at 06:47:35PM +0530, Chandra S Gorentla wrote:
> > During the clean-up of the function, it is need to check if
> > errors occurred, not the memory pointer.
> >
>
> The bug here is that we have a use after free on the success path. It
> should have been mentioned in the changelog.
>
> Anyway, this patch is buggy. If result == -EFAULT then it will crash.
> Also this patch is really ugly. There is someone who is going to send a
> correct fix (just add a return 0).
>
> This driver usese "do everything" style error handling. It is a bug
> prone anti-pattern because doing everything is more complicated than
> doing one thing. You can easily see it is bug prone, because it made
> you introduce a bug, right?
>
> Instead the error handling should look like this:
>
> return 0;
>
> err_free_msg:
> kfree(pstrMessage);
>
> return ret;
>
> There are no error paths where we need to free "pstrMessage->pvBuffer"
> but if we were to add one it would look like this:
>
> return 0;
>
> err_pvbuffer:
> kfree(pstrMessage->pvBuffer);
> err_msg:
> kfree(pstrMessage);
>
> return ret;
>
> This is a minimal, uncomplicated, no indenting, no if statement way of
> unwinding.
>
> regards,
> dan carpenter
>
OK. There is a problem in this patch. I will correct it, reorganize the
patch series.
Thank you,
chandra
prev parent reply other threads:[~2015-10-03 2:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-02 13:17 [PATCH 1/3] drivers: staging: wilc1000: Check for errors before kfree Chandra S Gorentla
2015-10-02 13:17 ` [PATCH 2/3] drivers: staging: wilc1000: Remove ineffective code Chandra S Gorentla
2015-10-02 13:17 ` [PATCH 3/3] drivers: staging: wilc1000: Do not return from function with lock is on Chandra S Gorentla
2015-10-02 13:39 ` [PATCH 1/3] drivers: staging: wilc1000: Check for errors before kfree Dan Carpenter
2015-10-03 2:11 ` Chandra Gorentla [this message]
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=20151003021112.GA9115@gcs-HP-Notebook \
--to=csgorentla@gmail.com \
--cc=chris.park@atmel.com \
--cc=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=johnny.kim@atmel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=rachel.kim@atmel.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;
as well as URLs for NNTP newsgroup(s).