From: Dave Young <dyoung@redhat.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Matt Fleming <matt.fleming@intel.com>,
linux-efi@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] efi: small leak on error
Date: Thu, 15 Jan 2015 20:22:17 +0800 [thread overview]
Message-ID: <20150115122217.GA16485@darkstar.redhat.com> (raw)
In-Reply-To: <20150115102824.GB6201@mwanda>
On 01/15/15 at 01:28pm, Dan Carpenter wrote:
> On Thu, Jan 15, 2015 at 05:54:55PM +0800, Dave Young wrote:
> > > out_add_entry:
> > > - for (j = i - 1; j > 0; j--) {
> > > + for (j = i - 1; j >= 0; j--) {
> > > entry = *(map_entries + j);
> > > kobject_put(&entry->kobj);
> > > }
> >
> > see below code, as for an invalid entry with i = 0, it will be not
> > assigned to *(map_entries + i)
>
> Yes. Of course, if the first iteration fails then we want the free loop
> to be a noop and it is in my code as well. j = -1. -1 is not >= 0.
> The problem is in later iterations.
>
> >
> > ---
> > for (i = 0; i < nr_efi_runtime_map; i++) {
> > entry = add_sysfs_runtime_map_entry(efi_kobj, i);
>
> Assume that this is the second iteration and "i == 1".
>
> > if (IS_ERR(entry)) {
> > ret = PTR_ERR(entry);
> > goto out_add_entry;
>
> Assume it fails so we hit this goto. We want to free the first entry.
>
> > }
> > *(map_entries + i) = entry;
> > }
> >
> > return 0;
> > out_add_entry:
> > for (j = i - 1; j > 0; j--) {
> > entry = *(map_entries + j);
>
> In your code, "j == 1 - 1" and that's not greater than zero so we don't
> enter this loop. In my code, we go through the loop one time.
>
> By the way this code would be a lot more clear if you used arrays.
> "map_entries[j]" is more clear than "*(map_entries + j)". Even in the
> other patch, passing "&foo[i]" is more clear than "foo + i".
Oops, I got your point, thanks. Will ack the patches.
I used to use the pointer, but if you want arrays, feel free to send a patch.
Thanks
Dave
next prev parent reply other threads:[~2015-01-15 12:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-15 9:21 [patch] efi: small leak on error Dan Carpenter
2015-01-15 9:54 ` Dave Young
[not found] ` <20150115095455.GA15197-4/PLUo9XfK/1wF9wiOj0lkEOCMrvLtNR@public.gmane.org>
2015-01-15 10:28 ` Dan Carpenter
2015-01-15 12:22 ` Dave Young [this message]
2015-01-15 12:24 ` Dave Young
2015-01-20 15:59 ` Matt Fleming
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=20150115122217.GA16485@darkstar.redhat.com \
--to=dyoung@redhat.com \
--cc=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=matt.fleming@intel.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