[U-Boot] C99 and dynamic arrays

Tom Rini trini at ti.com
Wed Mar 13 17:14:29 CET 2013


On Wed, Mar 13, 2013 at 03:41:33AM -0700, Simon Glass wrote:
> Hi Tom,
> 
> On Tue, Mar 12, 2013 at 4:48 PM, Tom Rini <tom.rini at gmail.com> wrote:
> > On Tue, Mar 12, 2013 at 7:22 PM, Simon Glass <sjg at google.com> wrote:
> >> Hi,
> >>
> >> Given that we seem to allow C99 features in U-Boot I wonder if it
> >> would be OK to use dynamic arrays in SPL?
> >>
> >> I am trying to replace:
> >>
> >> ptr = malloc(size);
> >>
> >> with:
> >>
> >> char ptr[size];
> >>
> >> to avoid use of malloc in SPL. Can I assume that is permitted?
> >
> > Without knowing the underlying mechanics of how that works, "maybe".
> > And we already have malloc in SPL thanks to FAT support.
> 
> If you see this patch:
> 
> http://patchwork.ozlabs.org/patch/209635/
> 
> In the function pow_mod(), I would like to replace:
> 
> val = malloc(key->len * sizeof(uint32_t));
> 
> with:
> 
> uint32_t val[key->len];
> 
> malloc() adds at least 1KB, perhaps 2KB.

Mans' point is pretty good.  If that's unexpectedly large you're
overflowing your stack and those errors suck.  Wolfgang proded me into
writing the HOWTO to see how much stack your SPL is using, worst case
due to how sucky those can be to debug.  Is 1-2KiB something you don't
have to spare in these cases?  Otherwise perhaps going with a static
allocation is the right call here since DDR is up (if you're doing
malloc already it must be..).

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130313/64b72d4b/attachment.pgp>


More information about the U-Boot mailing list