linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][V2] brcmfmac: fix leak of mypkt on error return path
@ 2019-04-09 11:43 Colin King
  2019-04-09 11:50 ` Arend Van Spriel
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Colin King @ 2019-04-09 11:43 UTC (permalink / raw)
  To: Arend van Spriel, Franky Lin, Hante Meuleman, Chi-Hsien Lin,
	Wright Feng, Kalle Valo, David S . Miller, linux-wireless,
	brcm80211-dev-list.pdl, brcm80211-dev-list, netdev
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently if the call to brcmf_sdiod_set_backplane_window fails then
then error return path leaks mypkt. Fix this by returning by a new
error path labelled 'out' that calls brcmu_pkt_buf_free_skb to free
mypkt.  Also remove redundant check on err before calling
brcmf_sdiod_skbuff_write.

Addresses-Coverity: ("Resource Leak")
Fixes: a7c3aa1509e2 ("brcmfmac: Remove brcmf_sdiod_addrprep()")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---

V2: Remove  redundant check on err before calling
brcmf_sdiod_skbuff_write, kudos to Dan Carpenter and Arend Van Spriel
for spotting this.

---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index ec129864cc9c..60aede5abb4d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -628,15 +628,13 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
 
 	err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
 	if (err)
-		return err;
+		goto out;
 
 	addr &= SBSDIO_SB_OFT_ADDR_MASK;
 	addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
 
-	if (!err)
-		err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2, addr,
-					       mypkt);
-
+	err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2, addr, mypkt);
+out:
 	brcmu_pkt_buf_free_skb(mypkt);
 
 	return err;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH][V2] brcmfmac: fix leak of mypkt on error return path
  2019-04-09 11:43 [PATCH][V2] brcmfmac: fix leak of mypkt on error return path Colin King
@ 2019-04-09 11:50 ` Arend Van Spriel
  2019-04-09 11:55   ` Dan Carpenter
  2019-04-10  9:17 ` Sergei Shtylyov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Arend Van Spriel @ 2019-04-09 11:50 UTC (permalink / raw)
  To: Colin King, Franky Lin, Hante Meuleman, Chi-Hsien Lin,
	Wright Feng, Kalle Valo, David S . Miller, linux-wireless,
	brcm80211-dev-list.pdl, brcm80211-dev-list, netdev
  Cc: kernel-janitors, linux-kernel

On 4/9/2019 1:43 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently if the call to brcmf_sdiod_set_backplane_window fails then
> then error return path leaks mypkt. Fix this by returning by a new
> error path labelled 'out' that calls brcmu_pkt_buf_free_skb to free
> mypkt.  Also remove redundant check on err before calling
> brcmf_sdiod_skbuff_write.
> 
> Addresses-Coverity: ("Resource Leak")
> Fixes: a7c3aa1509e2 ("brcmfmac: Remove brcmf_sdiod_addrprep()")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> 
> V2: Remove  redundant check on err before calling
> brcmf_sdiod_skbuff_write, kudos to Dan Carpenter and Arend Van Spriel
> for spotting this.
> 
> ---
>   drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> index ec129864cc9c..60aede5abb4d 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> @@ -628,15 +628,13 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
>   
>   	err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
>   	if (err)
> -		return err;
> +		goto out;
>   
>   	addr &= SBSDIO_SB_OFT_ADDR_MASK;
>   	addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
>   
> -	if (!err)
> -		err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2, addr,
> -					       mypkt);
> -
> +	err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2, addr, mypkt);
> +out:

I am fine with it, but my suggestion was a bit different:

	err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
	if (!err) {
		addr &= SBSDIO_SB_OFT_ADDR_MASK;
		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
		err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2,
					       addr, mypkt);
	}

>   	brcmu_pkt_buf_free_skb(mypkt);
>   
>   	return err;
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][V2] brcmfmac: fix leak of mypkt on error return path
  2019-04-09 11:50 ` Arend Van Spriel
@ 2019-04-09 11:55   ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-04-09 11:55 UTC (permalink / raw)
  To: Arend Van Spriel
  Cc: Colin King, Franky Lin, Hante Meuleman, Chi-Hsien Lin,
	Wright Feng, Kalle Valo, David S . Miller, linux-wireless,
	brcm80211-dev-list.pdl, brcm80211-dev-list, netdev,
	kernel-janitors, linux-kernel

On Tue, Apr 09, 2019 at 01:50:38PM +0200, Arend Van Spriel wrote:
> On 4/9/2019 1:43 PM, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > Currently if the call to brcmf_sdiod_set_backplane_window fails then
> > then error return path leaks mypkt. Fix this by returning by a new
> > error path labelled 'out' that calls brcmu_pkt_buf_free_skb to free
> > mypkt.  Also remove redundant check on err before calling
> > brcmf_sdiod_skbuff_write.
> > 
> > Addresses-Coverity: ("Resource Leak")
> > Fixes: a7c3aa1509e2 ("brcmfmac: Remove brcmf_sdiod_addrprep()")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> > 
> > V2: Remove  redundant check on err before calling
> > brcmf_sdiod_skbuff_write, kudos to Dan Carpenter and Arend Van Spriel
> > for spotting this.
> > 
> > ---
> >   drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 8 +++-----
> >   1 file changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> > index ec129864cc9c..60aede5abb4d 100644
> > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> > @@ -628,15 +628,13 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
> >   	err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
> >   	if (err)
> > -		return err;
> > +		goto out;
> >   	addr &= SBSDIO_SB_OFT_ADDR_MASK;
> >   	addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
> > -	if (!err)
> > -		err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2, addr,
> > -					       mypkt);
> > -
> > +	err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2, addr, mypkt);
> > +out:
> 
> I am fine with it, but my suggestion was a bit different:
> 
> 	err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
> 	if (!err) {
> 		addr &= SBSDIO_SB_OFT_ADDR_MASK;
> 		addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
> 		err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2,
> 					       addr, mypkt);
> 	}

Success handling always leads to extra indenting like this...  It's
less confusing to do failure handling keep the normal/success path at
indent level 1.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][V2] brcmfmac: fix leak of mypkt on error return path
  2019-04-09 11:43 [PATCH][V2] brcmfmac: fix leak of mypkt on error return path Colin King
  2019-04-09 11:50 ` Arend Van Spriel
@ 2019-04-10  9:17 ` Sergei Shtylyov
  2019-04-10  9:32 ` Mukesh Ojha
  2019-04-13 11:08 ` Kalle Valo
  3 siblings, 0 replies; 6+ messages in thread
From: Sergei Shtylyov @ 2019-04-10  9:17 UTC (permalink / raw)
  To: Colin King, Arend van Spriel, Franky Lin, Hante Meuleman,
	Chi-Hsien Lin, Wright Feng, Kalle Valo, David S . Miller,
	linux-wireless, brcm80211-dev-list.pdl, brcm80211-dev-list,
	netdev
  Cc: kernel-janitors, linux-kernel

On 09.04.2019 14:43, Colin King wrote:

> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently if the call to brcmf_sdiod_set_backplane_window fails then
> then error return path leaks mypkt. Fix this by returning by a new

    One "then" is enough. :-)

> error path labelled 'out' that calls brcmu_pkt_buf_free_skb to free
> mypkt.  Also remove redundant check on err before calling
> brcmf_sdiod_skbuff_write.
> 
> Addresses-Coverity: ("Resource Leak")
> Fixes: a7c3aa1509e2 ("brcmfmac: Remove brcmf_sdiod_addrprep()")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
[...]

MBR, Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][V2] brcmfmac: fix leak of mypkt on error return path
  2019-04-09 11:43 [PATCH][V2] brcmfmac: fix leak of mypkt on error return path Colin King
  2019-04-09 11:50 ` Arend Van Spriel
  2019-04-10  9:17 ` Sergei Shtylyov
@ 2019-04-10  9:32 ` Mukesh Ojha
  2019-04-13 11:08 ` Kalle Valo
  3 siblings, 0 replies; 6+ messages in thread
From: Mukesh Ojha @ 2019-04-10  9:32 UTC (permalink / raw)
  To: Colin King, Arend van Spriel, Franky Lin, Hante Meuleman,
	Chi-Hsien Lin, Wright Feng, Kalle Valo, David S . Miller,
	linux-wireless, brcm80211-dev-list.pdl, brcm80211-dev-list,
	netdev
  Cc: kernel-janitors, linux-kernel


On 4/9/2019 5:13 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently if the call to brcmf_sdiod_set_backplane_window fails then

Fix this one extra then pointed by Sergie.
otherwise looks good to me.

Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>

Cheers,
-Mukesh

> then error return path leaks mypkt. Fix this by returning by a new
> error path labelled 'out' that calls brcmu_pkt_buf_free_skb to free
> mypkt.  Also remove redundant check on err before calling
> brcmf_sdiod_skbuff_write.
>
> Addresses-Coverity: ("Resource Leak")
> Fixes: a7c3aa1509e2 ("brcmfmac: Remove brcmf_sdiod_addrprep()")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>
> V2: Remove  redundant check on err before calling
> brcmf_sdiod_skbuff_write, kudos to Dan Carpenter and Arend Van Spriel
> for spotting this.
>
> ---
>   drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> index ec129864cc9c..60aede5abb4d 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
> @@ -628,15 +628,13 @@ int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes)
>   
>   	err = brcmf_sdiod_set_backplane_window(sdiodev, addr);
>   	if (err)
> -		return err;
> +		goto out;
>   
>   	addr &= SBSDIO_SB_OFT_ADDR_MASK;
>   	addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
>   
> -	if (!err)
> -		err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2, addr,
> -					       mypkt);
> -
> +	err = brcmf_sdiod_skbuff_write(sdiodev, sdiodev->func2, addr, mypkt);
> +out:
>   	brcmu_pkt_buf_free_skb(mypkt);
>   
>   	return err;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][V2] brcmfmac: fix leak of mypkt on error return path
  2019-04-09 11:43 [PATCH][V2] brcmfmac: fix leak of mypkt on error return path Colin King
                   ` (2 preceding siblings ...)
  2019-04-10  9:32 ` Mukesh Ojha
@ 2019-04-13 11:08 ` Kalle Valo
  3 siblings, 0 replies; 6+ messages in thread
From: Kalle Valo @ 2019-04-13 11:08 UTC (permalink / raw)
  To: Colin King
  Cc: Arend van Spriel, Franky Lin, Hante Meuleman, Chi-Hsien Lin,
	Wright Feng, David S . Miller, linux-wireless,
	brcm80211-dev-list.pdl, brcm80211-dev-list, netdev,
	kernel-janitors, linux-kernel

Colin King <colin.king@canonical.com> wrote:

> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently if the call to brcmf_sdiod_set_backplane_window fails then
> error return path leaks mypkt. Fix this by returning by a new
> error path labelled 'out' that calls brcmu_pkt_buf_free_skb to free
> mypkt.  Also remove redundant check on err before calling
> brcmf_sdiod_skbuff_write.
> 
> Addresses-Coverity: ("Resource Leak")
> Fixes: a7c3aa1509e2 ("brcmfmac: Remove brcmf_sdiod_addrprep()")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>

Patch applied to wireless-drivers-next.git, thanks.

a927e8d8ab57 brcmfmac: fix leak of mypkt on error return path

-- 
https://patchwork.kernel.org/patch/10891135/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-04-13 11:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-09 11:43 [PATCH][V2] brcmfmac: fix leak of mypkt on error return path Colin King
2019-04-09 11:50 ` Arend Van Spriel
2019-04-09 11:55   ` Dan Carpenter
2019-04-10  9:17 ` Sergei Shtylyov
2019-04-10  9:32 ` Mukesh Ojha
2019-04-13 11:08 ` Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).