[U-Boot] Bombs away! Was: [PATCH 02/10] net: rtl8139: Add initialized eth_device structure

Mike Frysinger vapier at gentoo.org
Thu Oct 14 19:51:38 CEST 2010


On Thursday, October 14, 2010 04:29:51 Wolfgang Denk wrote:
> Reinhard Meyer wrote:
> > >   		dev = (struct eth_device *)malloc(sizeof *dev);
> > > 
> > > +		memset(dev, 0, sizeof(*dev));
> > > 
> > >   		sprintf (dev->name, "RTL8139#%d", card_number);
> > 
> > Apparently its quite common NOT to check malloc()'s possible
> > NULL return value... At least most NET drivers don't seem to...
> > 
> > Maybe another RFC to avoid duplicating code:
> > 
> > malloc_cleared_panic() to allocate and clear memory for a
> > really required structure and put a proper panic message if that
> > fails. Assuming that continuing u-boot once a driver cannot even
> > be initialized is futile, that would save even more code in each
> > driver.
> 
> Don't invent the wheel. If you really want to take that route, then
> copy existing solutions from other projects. Some of them use
> xmalloc() for this purpose; see for example BusyBox:
> http://git.busybox.net/busybox/tree/libbb/xfuncs_printf.c
> lines 44...51

yes, xmalloc/xzalloc/xrealloc are the commonly named funcs.  and we'll  
generally want zalloc too.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101014/ec5e897c/attachment.pgp 


More information about the U-Boot mailing list