diff options
author | Vladimir Oltean <vladimir.oltean@nxp.com> | 2021-02-16 14:32:13 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-02-17 00:52:57 +0300 |
commit | 6b73b7c96a91689b8167b1f7da0e89b997af0736 (patch) | |
tree | fe74c37b0395dda8abc8b6eeb43a5cde86af937a /drivers | |
parent | 42b5adbbac03bdb396192316c015fa3e64ffd5a1 (diff) | |
download | linux-6b73b7c96a91689b8167b1f7da0e89b997af0736.tar.xz |
net: dsa: felix: perform teardown on error in felix_setup
If the driver fails to probe, it would be nice to not leak memory.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/dsa/ocelot/felix.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index 3e72f0a79918..4a300ef41de6 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -1202,7 +1202,7 @@ static int felix_setup(struct dsa_switch *ds) err = ocelot_init(ocelot); if (err) - return err; + goto out_mdiobus_free; if (ocelot->ptp) { err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps); @@ -1227,7 +1227,7 @@ static int felix_setup(struct dsa_switch *ds) err = ocelot_devlink_sb_register(ocelot); if (err) - return err; + goto out_deinit_ports; for (port = 0; port < ds->num_ports; port++) { if (!dsa_is_cpu_port(ds, port)) @@ -1243,6 +1243,23 @@ static int felix_setup(struct dsa_switch *ds) ds->assisted_learning_on_cpu_port = true; return 0; + +out_deinit_ports: + for (port = 0; port < ocelot->num_phys_ports; port++) { + if (dsa_is_unused_port(ds, port)) + continue; + + ocelot_deinit_port(ocelot, port); + } + + ocelot_deinit_timestamp(ocelot); + ocelot_deinit(ocelot); + +out_mdiobus_free: + if (felix->info->mdio_bus_free) + felix->info->mdio_bus_free(ocelot); + + return err; } static void felix_teardown(struct dsa_switch *ds) |