All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaco Kroon <jaco@kroon.co.za>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] patch to fix initialization code of edd.c
Date: Sun, 30 Jul 2006 06:36:31 +0000	[thread overview]
Message-ID: <44CC536F.2050406@kroon.co.za> (raw)
In-Reply-To: <6b4e42d10607291831q7d2dbe26q6aec6406b093da8d@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 1752 bytes --]

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.
> 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]);
> 	}

i is unsigned and this code would crash for _all_ error values of i.
I'm thinking something like this might work better:

while(i-- > 0) {
        edd_device_unregister(edd_devices[i]);
        kfree(edd_devices[i]);
}

The reasoning here is that the device indicated by i is the one that
failed, in other words, it already didn't allocate, so if we get here
with i == 0 then we don't really have anything to de-allocate.  If we
get here with i == 1 then it means edd_devices[1] has _not_ been
allocated, but we do want to free for i == 0.

Comments?

Jaco
-- 
There are only 10 kinds of people in this world,
  those that understand binary and those that don't.
http://www.kroon.co.za/

[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/x-pkcs7-signature, Size: 3233 bytes --]

[-- Attachment #2: Type: text/plain, Size: 168 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

  parent reply	other threads:[~2006-07-30  6:36 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 ` Jaco Kroon [this message]
2006-07-30  8:09 ` [KJ] patch to fix initialization code of edd.c [3rd try] Om.
2006-07-30 21:34 ` [KJ] patch to fix initialization code of edd.c Neil Horman
2006-07-30 22:39 ` 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=44CC536F.2050406@kroon.co.za \
    --to=jaco@kroon.co.za \
    --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.