]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
net: smc911x: Fix potential memleak() in init fail path
authorMarek Vasut <marek.vasut+renesas@gmail.com>
Sun, 15 Mar 2020 14:57:14 +0000 (15:57 +0100)
committermarex <marex@desktop.lan>
Fri, 1 May 2020 10:35:21 +0000 (12:35 +0200)
Fix memleak in the init fail path, where if allocation or registration
of MDIO bus fails, then ethernet interface is not unregistered and the
private data are not freed, yet the probe function reports a failure.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
drivers/net/smc911x.c

index ceb4f81215212857c1c9830244f16684d6bfb82b..4459da5945d0072f41ad8d10eb58a47f1eb64900 100644 (file)
@@ -282,15 +282,23 @@ int smc911x_initialize(u8 dev_num, int base_addr)
 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
        int retval;
        struct mii_dev *mdiodev = mdio_alloc();
-       if (!mdiodev)
+       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)
+       if (retval < 0) {
+               mdio_free(mdiodev);
+               eth_unregister(dev);
+               free(dev);
                return retval;
+       }
 #endif
 
        return 1;