[U-Boot] [PATCH][v0] e1000_initialize: memset 0x0 nic and hw structure before their use

Wolfgang Denk wd at denx.de
Thu Nov 11 08:37:44 CET 2010


Dear Prabhakar,

In message <1289451431-22179-1-git-send-email-prabhakar at freescale.com> you wrote:
> nic and hw structures are allocated via malloc i.e. return memory
> is not zero initialized. Because of this few structure member like
> "function pointers" are initialized with garbage values.
> 
> It may cause problem. for eg. during eth_initialize, dev->write_hwaddr
> is used.

thanks. I already have a patch series "Add initialized eth_device
structure" on my stack.  I think this covers this, too.

>  		nic = (struct eth_device *) malloc(sizeof (*nic));
> +		if (nic)
> +			memset(nic, 0, sizeof (*nic));
> +		else
> +			return 0;

Please don't write code like that.  Why would the memset() [and only
this, none of the following code whch is in the same logioc branch?]
be in the if() branch?

Write instead:

	nic = (struct eth_device *) malloc(sizeof (*nic));
	if (!nic) {
		issue error message
		return error code
	}

	memset();
	...

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
Our missions are peaceful -- not for conquest.  When we do battle, it
is only because we have no choice.
	-- Kirk, "The Squire of Gothos", stardate 2124.5


More information about the U-Boot mailing list