net: smc911x: Pull MII registration into separate function
Pull the MII interface registration into separate function to avoid the ifdeffery in smc911x_initialize(). Moreover, adjust the fail path such that we use goto labels. Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com> Cc: Joe Hershberger <joe.hershberger@ni.com> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
@@ -240,12 +240,39 @@ static int smc911x_miiphy_write(struct mii_dev *bus, int phy, int devad,
|
|||||||
|
|
||||||
return smc911x_eth_phy_write(dev, phy, reg, val);
|
return smc911x_eth_phy_write(dev, phy, reg, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int smc911x_initialize_mii(struct eth_device *dev)
|
||||||
|
{
|
||||||
|
struct mii_dev *mdiodev = mdio_alloc();
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!mdiodev)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
|
||||||
|
mdiodev->read = smc911x_miiphy_read;
|
||||||
|
mdiodev->write = smc911x_miiphy_write;
|
||||||
|
|
||||||
|
ret = mdio_register(mdiodev);
|
||||||
|
if (ret < 0) {
|
||||||
|
mdio_free(mdiodev);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static int smc911x_initialize_mii(struct eth_device *dev)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int smc911x_initialize(u8 dev_num, int base_addr)
|
int smc911x_initialize(u8 dev_num, int base_addr)
|
||||||
{
|
{
|
||||||
unsigned long addrl, addrh;
|
unsigned long addrl, addrh;
|
||||||
struct eth_device *dev;
|
struct eth_device *dev;
|
||||||
|
int ret;
|
||||||
|
|
||||||
dev = calloc(1, sizeof(*dev));
|
dev = calloc(1, sizeof(*dev));
|
||||||
if (!dev)
|
if (!dev)
|
||||||
@@ -254,9 +281,10 @@ int smc911x_initialize(u8 dev_num, int base_addr)
|
|||||||
dev->iobase = base_addr;
|
dev->iobase = base_addr;
|
||||||
|
|
||||||
/* Try to detect chip. Will fail if not present. */
|
/* Try to detect chip. Will fail if not present. */
|
||||||
if (smc911x_detect_chip(dev)) {
|
ret = smc911x_detect_chip(dev);
|
||||||
free(dev);
|
if (ret) {
|
||||||
return 0;
|
ret = 0; /* Card not detected is not an error */
|
||||||
|
goto err_detect;
|
||||||
}
|
}
|
||||||
|
|
||||||
addrh = smc911x_get_mac_csr(dev, ADDRH);
|
addrh = smc911x_get_mac_csr(dev, ADDRH);
|
||||||
@@ -279,27 +307,15 @@ int smc911x_initialize(u8 dev_num, int base_addr)
|
|||||||
|
|
||||||
eth_register(dev);
|
eth_register(dev);
|
||||||
|
|
||||||
#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
|
ret = smc911x_initialize_mii(dev);
|
||||||
int retval;
|
if (ret)
|
||||||
struct mii_dev *mdiodev = mdio_alloc();
|
goto err_mii;
|
||||||
if (!mdiodev) {
|
|
||||||
eth_unregister(dev);
|
|
||||||
free(dev);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
|
|
||||||
mdiodev->read = smc911x_miiphy_read;
|
|
||||||
mdiodev->write = smc911x_miiphy_write;
|
|
||||||
|
|
||||||
retval = mdio_register(mdiodev);
|
|
||||||
if (retval < 0) {
|
|
||||||
mdio_free(mdiodev);
|
|
||||||
eth_unregister(dev);
|
|
||||||
free(dev);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
err_mii:
|
||||||
|
eth_unregister(dev);
|
||||||
|
err_detect:
|
||||||
|
free(dev);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user