Re: [PATCH 2.6.16] rndis_host/cdc_ether: add support for WindowsMobile 5 based devices

From: Andrew Morton
Date: Wed Mar 29 2006 - 18:36:29 EST


"Ole André Vadla Ravnås" <oleavr@xxxxxxxxx> wrote:
>
> + /* allocate and fill in the missing structures */
> + h = kmalloc(sizeof(struct usb_cdc_header_desc), GFP_KERNEL);
> + if (!h)
> + return -ENOMEM;
> + info->header = h;
> +
> + h->bLength = sizeof(struct usb_cdc_header_desc);
> + h->bDescriptorType = USB_DT_CS_INTERFACE;
> + h->bDescriptorSubType = USB_CDC_HEADER_TYPE;
> +
> + h->bcdCDC = 0; /* FIXME */
> +
> + u = kmalloc(sizeof(struct usb_cdc_union_desc), GFP_KERNEL);
> + if (!u)
> + return -ENOMEM;
> + info->u = u;

If the second kmalloc() fails, do we leak the memory at `h'?

Please don't sprinkle `return' statements deep inside large and complex
functions. It makes the code hard to audit and to modify and it invites
resource leaks and locking errors. Instead, use `goto suitable_unwind_point;', thanks.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/