[U-Boot] [PATCH] cs8900 driver: cleanup cs8900_initialize()

Ben Warren biggerbadderben at gmail.com
Thu Jan 21 22:10:45 CET 2010


Matthias Kaehlcke wrote:
> cs8900_initialize(): remove unecessary calls to free(), fix memory leak and
> report errors in the return value
>
> Signed-off-by: Matthias Kaehlcke <matthias at kaehlcke.net>
> ---
>  drivers/net/cs8900.c |    7 +++----
>  1 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/cs8900.c b/drivers/net/cs8900.c
> index df36004..7895048 100644
> --- a/drivers/net/cs8900.c
> +++ b/drivers/net/cs8900.c
> @@ -308,15 +308,14 @@ int cs8900_initialize(u8 dev_num, int base_addr)
>  
>  	dev = malloc(sizeof(*dev));
>  	if (!dev) {
> -		free(dev);
> -		return 0;
> +		return -1;
>   
'return 0' is actually correct.  It refers to the number of devices that 
were initialized.  Removing the 'free' calls is good, though.
>  	}
>  	memset(dev, 0, sizeof(*dev));
>  
>  	priv = malloc(sizeof(*priv));
>  	if (!priv) {
> -		free(priv);
> -		return 0;
> +		free(dev);
> +		return -1;
>  	}
>  	memset(priv, 0, sizeof(*priv));
>  	priv->regs = (struct cs8900_regs *)base_addr;
>   
regards,
Ben


More information about the U-Boot mailing list