[U-Boot] [PATCH] usb: Alloc buffer for USB descriptor dynamically

Stefan Bruens stefan.bruens at rwth-aachen.de
Sat Dec 19 22:23:25 CET 2015


On Saturday 19 December 2015 13:29:38 Simon Glass wrote:
> Hi Stafan,
> 
> On 19 December 2015 at 08:23, Stefan Bruens
> 
> <stefan.bruens at rwth-aachen.de> wrote:
> > On Friday 18 December 2015 15:41:10 Simon Glass wrote:
> >> Hi,
> >> 
> >> On 17 December 2015 at 18:07, Stefan Brüns <stefan.bruens at rwth-aachen.de>
> > 
> > wrote:
> >> > The configuration descriptor includes all interface, endpoint and
> >> > auxiliary descriptors (e.g. report, union) so 512 bytes may not be
> >> > enough.
> >> > 
> >> > Signed-off-by: Stefan Brüns <stefan.bruens at rwth-aachen.de>
> >> > ---
> >> > 
> >> >  common/usb.c  | 41 +++++++++++++++++++++++++++--------------
> >> >  include/usb.h |  5 +++--
> >> >  2 files changed, 30 insertions(+), 16 deletions(-)
> >> 
> >> Won't this call malloc() on every request? Can we avoid that?
> > 
> > This only affects the configuration descriptor, so one allocation per
> > device.
> > 
> > One could use a stack allocated buffer for small, e.g. 512 bytes,
> > descriptors, and use dynamic allocation only for larger one, but I don't
> > think this is worth the effort.
> > 
> > Kind regards,
> > 
> > Stefan
> 
> Another approach would be to have a single buffer for the USB stack
> and increase its size as needed. But if this is only once per device
> it does not seem worth it either.
> 
> Don't you need to free the buffer if usb_get_configuration_no()
> returns an error?

Yes, there's a free() missing in the error path.

Kind regards,

Stefan
-- 
Stefan Brüns  /  Bergstraße 21  /  52062 Aachen
home: +49 241 53809034     mobile: +49 151 50412019
work: +49 2405 49936-424


More information about the U-Boot mailing list