Skip to content

Commit cec279a

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: add error handling in sja1105_setup()
If any of sja1105_static_config_load(), sja1105_clocking_setup() or sja1105_devlink_setup() fails, we can't just return in the middle of sja1105_setup() or memory will leak. Add a cleanup path. Fixes: 0a7bdbc ("net: dsa: sja1105: move devlink param code to sja1105_devlink.c") Fixes: 8aa9ebc ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch") Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent dc596e3 commit cec279a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,13 +2976,13 @@ static int sja1105_setup(struct dsa_switch *ds)
29762976
rc = sja1105_static_config_load(priv, ports);
29772977
if (rc < 0) {
29782978
dev_err(ds->dev, "Failed to load static config: %d\n", rc);
2979-
return rc;
2979+
goto out_ptp_clock_unregister;
29802980
}
29812981
/* Configure the CGU (PHY link modes and speeds) */
29822982
rc = sja1105_clocking_setup(priv);
29832983
if (rc < 0) {
29842984
dev_err(ds->dev, "Failed to configure MII clocking: %d\n", rc);
2985-
return rc;
2985+
goto out_static_config_free;
29862986
}
29872987
/* On SJA1105, VLAN filtering per se is always enabled in hardware.
29882988
* The only thing we can do to disable it is lie about what the 802.1Q
@@ -3003,7 +3003,7 @@ static int sja1105_setup(struct dsa_switch *ds)
30033003

30043004
rc = sja1105_devlink_setup(ds);
30053005
if (rc < 0)
3006-
return rc;
3006+
goto out_static_config_free;
30073007

30083008
/* The DSA/switchdev model brings up switch ports in standalone mode by
30093009
* default, and that means vlan_filtering is 0 since they're not under
@@ -3012,6 +3012,17 @@ static int sja1105_setup(struct dsa_switch *ds)
30123012
rtnl_lock();
30133013
rc = sja1105_setup_8021q_tagging(ds, true);
30143014
rtnl_unlock();
3015+
if (rc)
3016+
goto out_devlink_teardown;
3017+
3018+
return 0;
3019+
3020+
out_devlink_teardown:
3021+
sja1105_devlink_teardown(ds);
3022+
out_ptp_clock_unregister:
3023+
sja1105_ptp_clock_unregister(ds);
3024+
out_static_config_free:
3025+
sja1105_static_config_free(&priv->static_config);
30153026

30163027
return rc;
30173028
}

0 commit comments

Comments
 (0)