public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Sergei Shtylyov <sshtylyov@ru•mvista.com>
To: Timur Tabi <timur@freescale•com>
Cc: linuxppc-dev@ozlabs•org, paulus@samba•org
Subject: Re: [PATCH] Check mac-address first in fsl_soc.c
Date: Fri, 09 Feb 2007 23:52:11 +0300	[thread overview]
Message-ID: <45CCDEFB.5050504@ru.mvista.com> (raw)
In-Reply-To: <11710513671236-git-send-email-timur@freescale.com>

Hello.

Timur Tabi wrote:
> The mac-address property in the device tree should be checked first,
> before local-mac-address.  This is because mac-address contains the most
> recent MAC address, whereas local-mac-address is the default address.
> Depending on the platform and the version of U-Boot, U-Boot will set
> one or the other, or both.

    Argh, *when* it will be setting both?

> This patch updates gfar_of_init() and fs_enet_of_init() to conform to
> this order.  It skips a property if it doesn't exist or if it contains
> an all-zero MAC address.  This patch also adds some NULL-pointer checking
> to make sure there are no panics if no MAC address has been passed.

> diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
> index 9f2a9a4..a0586ea 100644
> --- a/arch/powerpc/sysdev/fsl_soc.c
> +++ b/arch/powerpc/sysdev/fsl_soc.c
> @@ -233,12 +233,13 @@ static int __init gfar_of_init(void)
>  			goto err;
>  		}
>  
> -		mac_addr = get_property(np, "local-mac-address", NULL);
> -		if (mac_addr == NULL)
> -			mac_addr = get_property(np, "mac-address", NULL);
> -		if (mac_addr == NULL) {
> -			/* Obsolete */
> -			mac_addr = get_property(np, "address", NULL);
> +		mac_addr = get_property(np, "mac-address", NULL);
> +		if (!mac_addr || (memcmp(mac_addr, "\0\0\0\0\0", 6) == 0)) {
> +			mac_addr = get_property(np, "local-mac-address", NULL);
> +			if (!mac_addr || (memcmp(mac_addr, "\0\0\0\0\0", 6) == 0)) {
> +				/* Obsolete */
> +				mac_addr = get_property(np, "address", NULL);
> +			}
>  		}
>  
>  		if (mac_addr)
> @@ -607,7 +608,16 @@ static int __init fs_enet_of_init(void)
>  		}
>  
>  		mac_addr = get_property(np, "mac-address", NULL);
> -		memcpy(fs_enet_data.macaddr, mac_addr, 6);
> +		if (!mac_addr || (memcmp(mac_addr, "\0\0\0\0\0", 6) == 0)) {
> +			mac_addr = get_property(np, "local-mac-address", NULL);
> +			if (!mac_addr || (memcmp(mac_addr, "\0\0\0\0\0", 6) == 0)) {
> +				/* Obsolete */
> +				mac_addr = get_property(np, "address", NULL);
> +			}
> +		}
> +
> +		if (mac_addr)
> +			memcpy(fs_enet_data.macaddr, mac_addr, 6);
>  
>  		ph = get_property(np, "phy-handle", NULL);
>  		phy = of_find_node_by_phandle(*ph);
[...]
> @@ -891,8 +901,17 @@ static int __init fs_enet_of_init(void)
>  			goto err;
>  		r[0].name = enet_regs;
>  
> -		mac_addr = (void *)get_property(np, "mac-address", NULL);
> -		memcpy(fs_enet_data.macaddr, mac_addr, 6);
> +		mac_addr = get_property(np, "mac-address", NULL);
> +		if (!mac_addr || (memcmp(mac_addr, "\0\0\0\0\0", 6) == 0)) {
> +			mac_addr = get_property(np, "local-mac-address", NULL);
> +			if (!mac_addr || (memcmp(mac_addr, "\0\0\0\0\0", 6) == 0)) {
> +				/* Obsolete */
> +				mac_addr = get_property(np, "address", NULL);
> +			}
> +		}
> +
> +		if (mac_addr)
> +			memcpy(fs_enet_data.macaddr, mac_addr, 6);

    These are just asking to be put into a separate function... :-)

>  
>  		ph = (phandle *) get_property(np, "phy-handle", NULL);
>  		if (ph != NULL)

WBR, Sergei

  reply	other threads:[~2007-02-09 20:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-09 20:02 [PATCH] Check mac-address first in fsl_soc.c Timur Tabi
2007-02-09 20:52 ` Sergei Shtylyov [this message]
2007-02-09 20:55   ` Timur Tabi
2007-02-09 20:58     ` Sergei Shtylyov
2007-02-09 21:00       ` Timur Tabi
2007-02-09 21:06         ` Kumar Gala
2007-02-09 21:09           ` Timur Tabi
2007-02-13 17:25       ` Timur Tabi
2007-02-13 17:33         ` Sergei Shtylyov
2007-02-13 17:37           ` Timur Tabi
2007-02-13 17:37         ` Kumar Gala
2007-02-13 17:45           ` Timur Tabi
2007-02-13 18:01             ` Kumar Gala
2007-02-13 18:51               ` Timur Tabi
2007-02-13 19:01                 ` Kumar Gala
2007-02-13 19:10                   ` Timur Tabi
2007-02-13 19:20                   ` Timur Tabi
2007-02-13 19:50               ` Timur Tabi
2007-02-13 21:23                 ` Timur Tabi
2007-02-13 22:14                   ` Kumar Gala
2007-02-09 21:24 ` Jerry Van Baren
2007-02-09 21:51   ` Timur Tabi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45CCDEFB.5050504@ru.mvista.com \
    --to=sshtylyov@ru$(echo .)mvista.com \
    --cc=linuxppc-dev@ozlabs$(echo .)org \
    --cc=paulus@samba$(echo .)org \
    --cc=timur@freescale$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox