[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <84144f020708150716j55a0b904v846825cab2ab88eb@mail.gmail.com>
Date: Wed, 15 Aug 2007 17:16:45 +0300
From: "Pekka Enberg" <penberg@...helsinki.fi>
To: trenn@...e.de
Cc: linux-kernel <linux-kernel@...r.kernel.org>,
"Bjorn Helgaas" <bjorn.helgaas@...com>,
"Jean Delvare" <khali@...ux-fr.org>, abelay@...ell.com,
"Andi Kleen" <ak@...e.de>, linux-acpi <linux-acpi@...r.kernel.org>
Subject: Re: [PATCH] (for review and testing first) Implement dynamic allocated array for pnp port/io resources
Hi Thomas,
On 8/15/07, Thomas Renninger <trenn@...e.de> wrote:
> +int pnp_port_alloc (struct pnp_resource_table *res)
> +{
> + int ret = 0, i;
> + if (res->allocated_ports == 0) {
> + res->port_resource = kmalloc(sizeof(struct resource)
> + * PNP_ALLOC_PORTS,
> + GFP_KERNEL);
No need to use kmalloc() here. It's enough that you make sure
res->port_resource is NULL when res->allocated_ports is zero and
krealloc() will do the right thing.
On 8/15/07, Thomas Renninger <trenn@...e.de> wrote:
> + if (!res->port_resource) {
> + ret = -ENOMEM;
> + goto out;
> + }
> + } else {
> + res->port_resource = krealloc(res->port_resource,
> + (sizeof(struct resource)
> + * res->allocated_ports)
> + +
> + (sizeof(struct resource)
> + * PNP_ALLOC_PORTS),
> + GFP_KERNEL);
Assuming res->port_resource is non-NULL here and krealloc() fails,
you've leaked the originally allocated memory.
Pekka
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists