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

Nobuhiro Iwamatsu iwamatsu at nigauri.org
Thu Oct 14 09:45:09 CEST 2010


Hi,

2010/10/14 Reinhard Meyer <u-boot at emk-elektronik.de>:
> Dear All,
>>               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...

Oh, This is a stupid mistake.
Thanks.

>
> 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.

I think that a function such as kzalloc of the linux kernel is convenient.

Best regards,
  Nobuhiro

-- 
Nobuhiro Iwamatsu


More information about the U-Boot mailing list