Skip to contentSkip to conversation

davinci: cleanup davinci_sync_env_enetaddr() fucntion

PATCH New Manjunath Hadli 3 participants 3 messages Feb 10, 2012 – Jan 14, 2013 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 davinci: cleanup davinci_sync_env_enetaddr() fucntion

check for the return status for eth_getenv_enetaddr_by_index() and eth_setenv_enetaddr() functions and print appropriate message on failure.

Cc Tom Rini <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
Changes for v3:
undo conversion of debug statement to printf().

Changes for v2:
Removed additional check of comparing ethernet address is all zeros, As the core code already calls is_valid_ether_addr() and one of the checks in there is for all zeros.

 arch/arm/cpu/arm926ejs/davinci/misc.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
arch/arm/cpu/arm926ejs/davinci/misc.c +6 -3
index 5f510b6..c310c69 100644
@@ -101,9 +101,10 @@ void davinci_emac_mii_mode_sel(int mode_sel)
 void davinci_sync_env_enetaddr(uint8_t *rom_enetaddr)
 {
 	uint8_t env_enetaddr[6];
+	int ret;
 
-	eth_getenv_enetaddr_by_index("eth", 0, env_enetaddr);
-	if (!memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
+	ret = eth_getenv_enetaddr_by_index("eth", 0, env_enetaddr);
+	if (ret) {
 		/*
 		 * There is no MAC address in the environment, so we
 		 * initialize it from the value in the EEPROM.
@@ -111,8 +112,10 @@ void davinci_sync_env_enetaddr(uint8_t *rom_enetaddr)
 		debug("### Setting environment from EEPROM MAC address = "
 			"\"%pM\"\n",
 			env_enetaddr);
-		eth_setenv_enetaddr("ethaddr", rom_enetaddr);
+		ret = !eth_setenv_enetaddr("ethaddr", rom_enetaddr);
 	}
+	if (!ret)
+		printf("Failed to set mac address from EEPROM\n");
 }
 #endif	/* CONFIG_DRIVER_TI_EMAC */
 
Signature · 1 line
1.6.2.4
#2 lore raw

PATCH v3 1/1 davinci: cleanup davinci_sync_env_enetaddr() fucntion

In reply to Manjunath Hadli
Quoted 4 lines · Manjunath Hadli <manjunath.hadli <at> ti.com> writes:

check for the return status for eth_getenv_enetaddr_by_index() and eth_setenv_enetaddr() functions and print appropriate message on failure.

I am upgrading from v2011.12 (as I have some ubifsmount issues and don't want to debug this on an old ubi) and I saw that setting the MAC address from EEPROM is broken.

arch/arm/cpu/arm926ejs/davinci/misc.c void davinci_emac_mii_mode_sel(int mode_sel) · line 107

Quoted 3 lines
arch/arm/cpu/arm926ejs/davinci/misc.c +2 -1
-	if (!memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
+	ret = eth_getenv_enetaddr_by_index("eth", 0, env_enetaddr);
+	if (ret) {

In case there is no mac address in the environment the net/eth.c code will set env_enetaddr to all 0. This means that is_valid_ether_addr inside eth_getenv_enetaddr will return 0 (as of not valid). That also means that the below function will not be called.

I assume the right fix is to change the condition to !ret.

arch/arm/cpu/arm926ejs/davinci/misc.c void davinci_sync_env_enetaddr(uint8_t *rom_enetaddr) · line 118

Quoted 5 lines
arch/arm/cpu/arm926ejs/davinci/misc.c +3 -1
-		eth_setenv_enetaddr("ethaddr", rom_enetaddr);
+		ret = !eth_setenv_enetaddr("ethaddr", rom_enetaddr);
 	}
+	if (!ret)
+		printf("Failed to set mac address from EEPROM\n");

adding %d for 'ret' would be nice.