Subject: Re: [PATCH 04/50] adi/blackfin: set addr_assign_type correctly if random

From: Mike Frysinger <[email-masked]>
Date: Wed, 8 Feb 2012 23:05:13 -0500

On Wednesday 08 February 2012 16:10:11 Danny Kukawka wrote:
> --- a/arch/blackfin/mach-bf537/boards/cm_bf537e.c
> +++ b/arch/blackfin/mach-bf537/boards/cm_bf537e.c
> 
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>  	random_ether_addr(addr);
>  	printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n",
> 		__FILE__, __func__);
> +	return 1;
>  }

these boards that just call random_ether_addr() should be changed to only 
return 1 ...

> --- a/drivers/net/ethernet/adi/bfin_mac.c
> +++ b/drivers/net/ethernet/adi/bfin_mac.c
> @@ -621,6 +621,8 @@
>
>  	memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
> +	if (dev->addr_assign_type & NET_ADDR_RANDOM)
> +		dev->addr_assign_type ^= NET_ADDR_RANDOM;
>  	setup_mac_addr(dev->dev_addr);
>  	return 0;
>  }
> @@ -1496,12 +1498,14 @@
>
> -	if (!is_valid_ether_addr(ndev->dev_addr))
> -		bfin_get_ether_addr(ndev->dev_addr);
> +	if (!is_valid_ether_addr(ndev->dev_addr)) {
> +		if (bfin_get_ether_addr(ndev->dev_addr))
> +			ndev->addr_assign_type |= NET_ADDR_RANDOM;
> +	}

if it returned non-zero, then the mac addr is still invalid, so down below ...

>  	/* If still not valid, get a random one */
>  	if (!is_valid_ether_addr(ndev->dev_addr))
> -		random_ether_addr(ndev->dev_addr);
> +		dev_hw_addr_random(ndev, ndev->dev_addr);

... we call dev_hw_addr_random(), so explicitly setting NET_ADDR_RANDOM 
ourselves is unnecessary

i think the logic should read:
	if (!is_valid_ether_addr(ndev->dev_addr)) {
		if (bfin_get_ether_addr(ndev->dev_addr))
			goto random_mac;

	if (!is_valid_ether_addr(ndev->dev_addr))
 random_mac:
		dev_hw_addr_random(ndev, ndev->dev_addr);
-mike