diff mbox series

[v2] net: dsa: sja1105: prevent leaking memory

Message ID 20190918180439.12441-1-navid.emamdoost@gmail.com
State Changes Requested
Delegated to: David Miller
Headers show
Series [v2] net: dsa: sja1105: prevent leaking memory | expand

Commit Message

Navid Emamdoost Sept. 18, 2019, 6:04 p.m. UTC
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)

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/net/dsa/sja1105/sja1105_spi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Vladimir Oltean Sept. 18, 2019, 8 p.m. UTC | #1
Hi Navid,

Thanks for the patch.

On 9/18/19 9:04 PM, Navid Emamdoost wrote:
> 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")

> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>   drivers/net/dsa/sja1105/sja1105_spi.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/dsa/sja1105/sja1105_spi.c b/drivers/net/dsa/sja1105/sja1105_spi.c
> index 84dc603138cf..58dd37ecde17 100644
> --- a/drivers/net/dsa/sja1105/sja1105_spi.c
> +++ b/drivers/net/dsa/sja1105/sja1105_spi.c
> @@ -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
> 

Regards,
-Vladimir
David Miller Sept. 19, 2019, 8:10 a.m. UTC | #2
From: Vladimir Oltean <olteanv@gmail.com>
Date: Wed, 18 Sep 2019 23:00:20 +0300

> Hi Navid,
> 
> Thanks for the patch.
> 
> On 9/18/19 9:04 PM, Navid Emamdoost wrote:
>> 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")

However the Fixes: line should not be broken up like this with newlines.
Vladimir Oltean Sept. 19, 2019, 8:20 a.m. UTC | #3
On Thu, 19 Sep 2019 at 11:11, David Miller <davem@davemloft.net> wrote:
>
> From: Vladimir Oltean <olteanv@gmail.com>
> Date: Wed, 18 Sep 2019 23:00:20 +0300
>
> > Hi Navid,
> >
> > Thanks for the patch.
> >
> > On 9/18/19 9:04 PM, Navid Emamdoost wrote:
> >> 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")
>
> However the Fixes: line should not be broken up like this with newlines.

Sorry, my mail client did that automatically.

-Vladimir
diff mbox series

Patch

diff --git a/drivers/net/dsa/sja1105/sja1105_spi.c b/drivers/net/dsa/sja1105/sja1105_spi.c
index 84dc603138cf..58dd37ecde17 100644
--- a/drivers/net/dsa/sja1105/sja1105_spi.c
+++ b/drivers/net/dsa/sja1105/sja1105_spi.c
@@ -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