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

Simon Glass sjg at chromium.org
Sat Dec 19 21:29:38 CET 2015


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?

Otherwise:

Reviewed-by: Simon Glass <sjg at chromium.org>

Regards,
Simon


More information about the U-Boot mailing list