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

Wolfgang Denk wd at denx.de
Thu Oct 14 10:36:46 CEST 2010


Dear Nobuhiro Iwamatsu,

In message <AANLkTikEa5OLvCEmNSJZtoddBrMk50=Zr=nv0CyL5VDy at mail.gmail.com> you wrote:
>
> >>               dev = (struct eth_device *)malloc(sizeof *> dev);
> >> +             memset(dev, 0, sizeof(*dev));
> >>
> >>               sprintf (dev->name, "RTL8139#%d", card_numbe> r);
> >
> > 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.

I just want to point out that this was not your mistake!

The existing code did not check the return code either.

So actually you fixed a bug, while Reinhard noticed another,
unrelated bug.


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

Yes, but it needs careful consideration about how to handle malloc()
errors. It may not always be appropriate to crash the whole system.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"I go on working for the same reason a hen goes on laying eggs."
- H. L. Mencken


More information about the U-Boot mailing list