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

From: Ole André Vadla Ravnås
Date: Wed Mar 29 2006 - 22:12:34 EST


On 3/30/06, Andrew Morton <akpm@xxxxxxxx> wrote:
> "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.

Ahh, very good point there! Thanks for pointing it out! I'll fix it,
wait for a comment from David, and then resubmit.

Cheers,
Ole Andre
-
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/