Re: [PATCH] (for review and testing first) Implement dynamic allocated array for pnp port/io resources

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Thomas,

On 8/15/07, Thomas Renninger <[email protected]> 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 <[email protected]> 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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux