[U-Boot] [PATCH] net: e1000: Add initialized eth_device & e1000_hw structure

Paul Gortmaker paul.gortmaker at windriver.com
Fri Nov 12 18:59:14 CET 2010


On Fri, Nov 12, 2010 at 5:13 AM, Kumar Gala <galak at kernel.crashing.org> 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.
>
> Signed-off-by: Kumar Gala <galak at kernel.crashing.org>
> ---
>  drivers/net/e1000.c |   14 ++++++++++++++
>  1 files changed, 14 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c
> index 2825342..911eb2c 100644
> --- a/drivers/net/e1000.c
> +++ b/drivers/net/e1000.c
> @@ -5177,7 +5177,21 @@ e1000_initialize(bd_t * bis)
>                }
>
>                nic = (struct eth_device *) malloc(sizeof (*nic));
> +               if (!nic) {
> +                       printf("Error: e1000 - Can not alloc memory\n");
> +                       return 0;
> +               }
> +
>                hw = (struct e1000_hw *) malloc(sizeof (*hw));
> +               if (!nic) {

Copy and paste error, I think you want "if (!hw)"

Paul.

> +                       free(nic);
> +                       printf("Error: e1000 - Can not alloc memory\n");
> +                       return 0;
> +               }
> +
> +               memset(nic, 0, sizeof(*dev));
> +               memset(hw, 0, sizeof(*hw));
> +
>                hw->pdev = devno;
>                nic->priv = hw;
>
> --
> 1.7.2.3
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>


More information about the U-Boot mailing list