[U-Boot-Users] uninitialized list_head in miiphy routines

Hi,
I experienced some trouble with the new PHY code on our 4xx boards. The code seems to be added on october, 28th.
This is what happens: When our boards wake up for the very first time no ethaddr is configured. Therefore no network interface will be available (you get the message: 'Net: no ethernet found.'). This will prevent miiphy_register() to be called. This function initializes a list with all PHYs (mii_devs). When this function is never called before any of the miiphy functions is called, these functions will crash during the search (list_for_each(...)) for the correct PHY driver.
This happens in our implementation of reset_phy() (board/esd/cms700/cms700.c).
I expect the miiphy functions to return with an error when a PHY interface is not availble. This will ony work when the mii_devs list_head is initilized in any case.
I appended a little patch that introduces miiphy_init() that must be called before any miiphy function. The patch is tested on 4xx systems.
Are there any better ways to do it?
Wolfgang, do you accept this patch?
Regards Matthias
diff --git a/common/miiphyutil.c b/common/miiphyutil.c --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -58,6 +58,12 @@ struct mii_dev { static struct list_head mii_devs; static struct mii_dev *current_mii;
+void miiphy_init(void) +{ + INIT_LIST_HEAD(&mii_devs); + current_mii = NULL; +} + /***************************************************************************** * * Register read and write MII access routines for the device <name>. diff --git a/cpu/ppc4xx/4xx_enet.c b/cpu/ppc4xx/4xx_enet.c --- a/cpu/ppc4xx/4xx_enet.c +++ b/cpu/ppc4xx/4xx_enet.c @@ -1360,6 +1360,10 @@ int ppc_4xx_eth_initialize (bd_t * bis) #endif #endif
+#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) + miiphy_init(); +#endif + for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
/* See if we can actually bring up the interface, otherwise, skip it */ diff --git a/include/miiphy.h b/include/miiphy.h --- a/include/miiphy.h +++ b/include/miiphy.h @@ -62,6 +62,7 @@ void miiphy_register(char *devname, int miiphy_set_current_dev(char *devname); char *miiphy_get_current_dev(void);
+void miiphy_init(void); void miiphy_listdev(void);
#define BB_MII_DEVNAME "bbmii"
participants (1)
-
Matthias Fuchs