Skip to contentSkip to conversation

net: dsa: sja1105: prevent leaking memory

PATCH Superseded Navid Emamdoost 4 participants 9 messages Sep 18, 2019 – Sep 19, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/net/dsa/sja1105/sja1105_spi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/dsa/sja1105/sja1105_spi.c +5 -3
index 84dc603138cf..80e86c714efb 100644
@@ -408,8 +408,9 @@ int sja1105_static_config_upload(struct sja1105_private *priv)
 
 	rc = static_config_buf_prepare_for_upload(priv, config_buf, buf_len);
 	if (rc < 0) {
-		dev_err(dev, "Invalid config, cannot upload\n");
-		return -EINVAL;
+		dev_err(dev, "Invalid config, cannot upload\n");
+		rc = -EINVAL;
+		goto out;
 	}
 	/* Prevent PHY jabbering during switch reset by inhibiting
 	 * 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);
 	if (rc < 0) {
 		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
 	 * (reach IFG). It is guaranteed that a second one will not
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 5 lines · Navid Emamdoost

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.

Hi Navid

Please could you provide a Fixes: tag for where this memory leak was introduced.

Quoted 9 lines
---
 drivers/net/dsa/sja1105/sja1105_spi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/dsa/sja1105/sja1105_spi.c +0 -0
index 84dc603138cf..80e86c714efb 100644

drivers/net/dsa/sja1105/sja1105_spi.c int sja1105_static_config_upload(struct sja1105_private *priv) · line 411

Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_spi.c +1 -2
@@ -408,8 +408,9 @@ int sja1105_static_config_upload(struct sja1105_private *priv)
 
 	rc = static_config_buf_prepare_for_upload(priv, config_buf, buf_len);
 	if (rc < 0) {
-		dev_err(dev, "Invalid config, cannot upload\n");
-		return -EINVAL;
+		dev_err(dev, "Invalid config, cannot upload\n");

What changed in this dev_err() call?

Thanks
Andrew

#2 lore raw

PATCH v2 1/1 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 8aa9ebccae876 (avoid leaking config_buf)
Fixes 1a4c69406cc1c (avoid leaking config_buf)
---
 drivers/net/dsa/sja1105/sja1105_spi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_spi.c +4 -2
index 84dc603138cf..58dd37ecde17 100644
@@ -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);
 	if (rc < 0) {
 		dev_err(dev, "Invalid config, cannot upload\n");
-		return -EINVAL;
+		rc = -EINVAL;
+		goto out;
 	}
 	/* Prevent PHY jabbering during switch reset by inhibiting
 	 * 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);
 	if (rc < 0) {
 		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
 	 * (reach IFG). It is guaranteed that a second one will not
Signature · 1 line
2.17.1
maintainer
#3 lore raw

Hi Navid,

Thanks for the patch.

Quoted 7 lines · Navid Emamdoost

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 8aa9ebccae876 (avoid leaking config_buf)
Fixes 1a4c69406cc1c (avoid leaking config_buf)

You're not supposed to add a short description of the patch here, but rather the commit message of the patch you're fixing. Add this to your ~/.gitconfig:

[pretty]

	fixes = Fixes: %h (\"%s\")

And then run:
git show --pretty=fixes 8aa9ebccae87621d997707e4f25e53fddd7e30e4

Fixes 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch")

git show --pretty=fixes 1a4c69406cc1c3c42bb7391c8eb544e93fe9b320

Fixes 1a4c69406cc1 ("net: dsa: sja1105: Prevent PHY jabbering during switch reset")
Quoted 21 lines
---
  drivers/net/dsa/sja1105/sja1105_spi.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_spi.c +2 -1
index 84dc603138cf..58dd37ecde17 100644
@@ -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);
  	if (rc < 0) {
  		dev_err(dev, "Invalid config, cannot upload\n");
-		return -EINVAL;
+		rc = -EINVAL;
+		goto out;
  	}
  	/* Prevent PHY jabbering during switch reset by inhibiting
  	 * Tx on all ports and waiting for current packet to drain.

drivers/net/dsa/sja1105/sja1105_spi.c int sja1105_static_config_upload(struct sja1105_private *priv) · line 426

Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_spi.c +2 -1
@@ -418,7 +419,8 @@ int sja1105_static_config_upload(struct sja1105_private *priv)
  	rc = sja1105_inhibit_tx(priv, port_bitmap, true);
  	if (rc < 0) {
  		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
  	 * (reach IFG). It is guaranteed that a second one will not

Regards,
-Vladimir

#4 lore raw

PATCH v3 1/1 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 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port

L2 switch")

Fixes 1a4c69406cc1 ("net: dsa: sja1105: Prevent PHY jabbering during

switch reset")

---
 drivers/net/dsa/sja1105/sja1105_spi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_spi.c +4 -2
index 84dc603138cf..58dd37ecde17 100644
@@ -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);
 	if (rc < 0) {
 		dev_err(dev, "Invalid config, cannot upload\n");
-		return -EINVAL;
+		rc = -EINVAL;
+		goto out;
 	}
 	/* Prevent PHY jabbering during switch reset by inhibiting
 	 * 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);
 	if (rc < 0) {
 		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
 	 * (reach IFG). It is guaranteed that a second one will not
Signature · 1 line
2.17.1
maintainer Reviewed-by on v3 1/1
#5 lore raw
Quoted 5 lines · Navid Emamdoost

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.

Quoted 8 lines
Fixes 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port

L2 switch")

Fixes 1a4c69406cc1 ("net: dsa: sja1105: Prevent PHY jabbering during

switch reset")

---

Quoted 30 lines
 drivers/net/dsa/sja1105/sja1105_spi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_spi.c +4 -3
index 84dc603138cf..58dd37ecde17 100644
@@ -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);
        if (rc < 0) {
                dev_err(dev, "Invalid config, cannot upload\n");
-               return -EINVAL;
+               rc = -EINVAL;
+               goto out;
        }
        /* Prevent PHY jabbering during switch reset by inhibiting
         * 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);
        if (rc < 0) {
                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
         * (reach IFG). It is guaranteed that a second one will not
--

2.17.1

maintainer
#6 lore raw
In reply to Navid Emamdoost

From: Navid Emamdoost <[email protected]>
Date: Wed, 18 Sep 2019 15:34:06 -0500

Quoted 5 lines
Fixes 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port

L2 switch")

Fixes 1a4c69406cc1 ("net: dsa: sja1105: Prevent PHY jabbering during

switch reset")

Please:

1) Do not break Fixes: tags into multiples lines, that way the string is easily greppable.

2) Do not separate the Fixes: from other tags with newlines. It is just another tag like Signed-off-by: and Acked-by:

Thanks.

maintainer
#7 lore raw
In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>
Date: Wed, 18 Sep 2019 23:00:20 +0300

Quoted 22 lines

Hi Navid,

Thanks for the patch.

Quoted 6 lines · Navid Emamdoost

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 8aa9ebccae876 (avoid leaking config_buf)
Fixes 1a4c69406cc1c (avoid leaking config_buf)

You're not supposed to add a short description of the patch here, but rather the commit message of the patch you're fixing.
Add this to your ~/.gitconfig:

[pretty]

	fixes = Fixes: %h (\"%s\")

And then run:
git show --pretty=fixes 8aa9ebccae87621d997707e4f25e53fddd7e30e4

Quoted 7 lines
Fixes 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105

5-port L2 switch")

git show --pretty=fixes 1a4c69406cc1c3c42bb7391c8eb544e93fe9b320

Fixes 1a4c69406cc1 ("net: dsa: sja1105: Prevent PHY jabbering during

switch reset")

However the Fixes: line should not be broken up like this with newlines.

maintainer
#8 lore raw
Quoted 29 lines · David Miller

From: Vladimir Oltean <[email protected]>
Date: Wed, 18 Sep 2019 23:00:20 +0300

Quoted 25 lines

Hi Navid,

Thanks for the patch.

Quoted 6 lines · Navid Emamdoost

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 8aa9ebccae876 (avoid leaking config_buf)
Fixes 1a4c69406cc1c (avoid leaking config_buf)

You're not supposed to add a short description of the patch here, but rather the commit message of the patch you're fixing.
Add this to your ~/.gitconfig:

[pretty]

      fixes = Fixes: %h (\"%s\")

And then run:
git show --pretty=fixes 8aa9ebccae87621d997707e4f25e53fddd7e30e4

Fixes 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105

5-port L2 switch")

Quoted 6 lines
Quoted 4 lines

git show --pretty=fixes 1a4c69406cc1c3c42bb7391c8eb544e93fe9b320

Fixes 1a4c69406cc1 ("net: dsa: sja1105: Prevent PHY jabbering during

switch reset")

However the Fixes: line should not be broken up like this with newlines.

Sorry, my mail client did that automatically.

-Vladimir