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 01:56:36 +0000 [thread overview]
Message-ID: <20060730015636.GA10030@localhost.localdomain> (raw)
In-Reply-To: <6b4e42d10607291831q7d2dbe26q6aec6406b093da8d@mail.gmail.com>
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?
Regards
Neil
> Signed-off-by: Om Nara<xhandle@gmail.com>
>
> drivers/firmware/edd.c | 27 +++++++++++++++++++--------
> 1 files changed, 19 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
> index b4502ed..036dfc6 100644
> --- a/drivers/firmware/edd.c
> +++ b/drivers/firmware/edd.c
> @@ -739,6 +739,7 @@ static int __init
> edd_init(void)
> {
> unsigned int i;
> + unsigned int failno;
> int rc=0;
> struct edd_device *edev;
>
> @@ -754,21 +755,31 @@ edd_init(void)
> if (rc)
> return rc;
>
> - for (i = 0; i < edd_num_devices() && !rc; i++) {
> + for (i = 0, failno = 0; i < edd_num_devices(); i++) {
> edev = kzalloc(sizeof (*edev), GFP_KERNEL);
> - if (!edev)
> - return -ENOMEM;
> -
> + if (!edev) {
> + failno = i;
> + rc = -ENOMEM;
> + goto alloc_fail;
> + }
> rc = edd_device_register(edev, i);
> if (rc) {
> - kfree(edev);
> - break;
> + failno = i;
> + goto devreg_fail;
> }
> edd_devices[i] = edev;
> }
> + return rc;
>
> - if (rc)
> - firmware_unregister(&edd_subsys);
> +devreg_fail:
> + kfree (edev);
> +
> +alloc_fail:
> + for (i = 0; i < failno; i++) {
> + edd_device_unregister (edd_devices[i]);
> + kfree (edd_devices[i]);
> + }
> + firmware_unregister(&edd_subsys);
> return rc;
> }
> _______________________________________________
> Kernel-janitors mailing list
> Kernel-janitors@lists.osdl.org
> https://lists.osdl.org/mailman/listinfo/kernel-janitors
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
next prev parent reply other threads:[~2006-07-30 1:56 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 [this message]
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 ` [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=20060730015636.GA10030@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.