All of lore.kernel.org
 help / color / mirror / Atom feed
From: Neil Horman <nhorman@tuxdriver.com>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] patch to fix initialization code of edd.c
Date: Sun, 30 Jul 2006 21:34:57 +0000	[thread overview]
Message-ID: <20060730213457.GA32045@localhost.localdomain> (raw)
In-Reply-To: <6b4e42d10607291831q7d2dbe26q6aec6406b093da8d@mail.gmail.com>

On Sat, Jul 29, 2006 at 10:52:37PM -0700, Om. wrote:
> On 7/29/06, Neil Horman <nhorman@tuxdriver.com> wrote:
> >On Sat, Jul 29, 2006 at 06:31:49PM -0700, Om. wrote:
> >> Hi,
> >> BIOS Enhanced Disk Drive Services (EDD) driver's failed return from
> >> the init function causes memory leaks in src/drivers/firmware/edd.c
> >> This is my first patch submission. It is generated against 2.6.18-rc2.
> >>
> >> Review comments welcome.
> >> Regards,
> >> Om.
> >>
> >Looks good, but instead of adding a stack variable failno to free the 
> >allocated
> >devices on failure, why not just use the same i variable and count 
> >backwards in
> >the loop under alloc_fail?
> I tried that first. But there would be some ambiguity between i=0 as a
> failure and i=0 as a success.
Ok, so remove the ambiguity from inside the for loop.  You have a few choices.
You can:

for (i=-1; i< edd_num_devices; ) {
....
i++;
edd_devices[i] = edev;

better still, right before you execute either of your goto's, just replace the
failno = i with a i--;, that way if you fail on the first iteration, i will
underflow to -1, and the freeing for loop will just get skipped.  And you save
an int worth of stack, which, while small, can be significant given that we're
building with single page stacks now.

thanks & regards
Neil

> What I meant is,
> 	int i;
> ...
> 	for (i = 0; i < edd_num_devices(); i++) {
> 		edev = kzalloc(sizeof (*edev), GFP_KERNEL);
> 		if (!edev) {
> 			rc = -ENOMEM;
> 			goto alloc_fail;
> 		}
> ....
> 		edd_devices[i] = edev;
> 	}
> ...
> alloc_fail:
> 	for (; i >= 0; i--) {
> 		edd_device_unregister (edd_devices[i]);
> 		kfree (edd_devices[i]);
> 	}
> ...
> Such code crash for the failure case of i=0. To avoid without another
> variable, I would have to resort to something like,
> 		if (!edev) {
> 			rc = -ENOMEM;
>                        /* keep a flag, modify the value of i ...etc
> to distinguish between success and failure*/
> 			goto alloc_fail;
> 		}
> which I thought ugly.
> 
> What is your opinion on this?
> Regards,
> Om.
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

  parent reply	other threads:[~2006-07-30 21:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-30  1:31 [KJ] patch to fix initialization code of edd.c Om.
2006-07-30  1:56 ` Neil Horman
2006-07-30  5:26 ` Jesper Juhl
2006-07-30  5:52 ` Om.
2006-07-30  6:13 ` [KJ] patch to fix initialization code of edd.c [2nd try] Om.
2006-07-30  6:36 ` [KJ] patch to fix initialization code of edd.c Jaco Kroon
2006-07-30  8:09 ` [KJ] patch to fix initialization code of edd.c [3rd try] Om.
2006-07-30 21:34 ` Neil Horman [this message]
2006-07-30 22:39 ` [KJ] patch to fix initialization code of edd.c Om.

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=20060730213457.GA32045@localhost.localdomain \
    --to=nhorman@tuxdriver.com \
    --cc=kernel-janitors@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.