X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fmiiphyutil.c;h=7e41957185072123a81468309081ec4586730867;hb=eb04ab3492297941b285ff552645cc1c0ed72edb;hp=74812e6e1b959a0edf78801e1c3dd77116b027c2;hpb=5b9c79a81db80c3f9e50c77477957cd803429af8;p=oweals%2Fu-boot.git diff --git a/common/miiphyutil.c b/common/miiphyutil.c index 74812e6e1b..7e41957185 100644 --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -11,6 +11,7 @@ */ #include +#include #include #include @@ -113,6 +114,8 @@ void miiphy_register(const char *name, if (new_dev == NULL || ldev == NULL) { printf("miiphy_register: cannot allocate memory for '%s'\n", name); + free(ldev); + mdio_free(new_dev); return; } @@ -151,9 +154,14 @@ struct mii_dev *mdio_alloc(void) return bus; } +void mdio_free(struct mii_dev *bus) +{ + free(bus); +} + int mdio_register(struct mii_dev *bus) { - if (!bus || !bus->name || !bus->read || !bus->write) + if (!bus || !bus->read || !bus->write) return -1; /* check if we have unique name */ @@ -172,6 +180,20 @@ int mdio_register(struct mii_dev *bus) return 0; } +int mdio_unregister(struct mii_dev *bus) +{ + if (!bus) + return 0; + + /* delete it from the list */ + list_del(&bus->link); + + if (current_mii == bus) + current_mii = NULL; + + return 0; +} + void mdio_list_devices(void) { struct list_head *entry;