net: dsa: sja1105: Prevent leaking memory

In sja1105_static_config_upload, in two cases memory is leaked: when
static_config_buf_prepare_for_upload fails and when sja1105_inhibit_tx
fails. In both cases config_buf should be released.

Fixes: 8aa9ebccae ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch")
Fixes: 1a4c69406c ("net: dsa: sja1105: Prevent PHY jabbering during switch reset")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Navid Emamdoost 2019-09-29 01:43:39 +03:00 committed by David S. Miller
parent b6f2494d31
commit 68501df92d
1 changed files with 4 additions and 2 deletions

View File

@ -409,7 +409,8 @@ int sja1105_static_config_upload(struct sja1105_private *priv)
rc = static_config_buf_prepare_for_upload(priv, config_buf, buf_len); rc = static_config_buf_prepare_for_upload(priv, config_buf, buf_len);
if (rc < 0) { if (rc < 0) {
dev_err(dev, "Invalid config, cannot upload\n"); dev_err(dev, "Invalid config, cannot upload\n");
return -EINVAL; rc = -EINVAL;
goto out;
} }
/* Prevent PHY jabbering during switch reset by inhibiting /* Prevent PHY jabbering during switch reset by inhibiting
* Tx on all ports and waiting for current packet to drain. * Tx on all ports and waiting for current packet to drain.
@ -418,7 +419,8 @@ int sja1105_static_config_upload(struct sja1105_private *priv)
rc = sja1105_inhibit_tx(priv, port_bitmap, true); rc = sja1105_inhibit_tx(priv, port_bitmap, true);
if (rc < 0) { if (rc < 0) {
dev_err(dev, "Failed to inhibit Tx on ports\n"); dev_err(dev, "Failed to inhibit Tx on ports\n");
return -ENXIO; rc = -ENXIO;
goto out;
} }
/* Wait for an eventual egress packet to finish transmission /* Wait for an eventual egress packet to finish transmission
* (reach IFG). It is guaranteed that a second one will not * (reach IFG). It is guaranteed that a second one will not