All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Arend Van Spriel <arend.vanspriel@broadcom.com>
Cc: Colin King <colin.king@canonical.com>,
	Franky Lin <franky.lin@broadcom.com>,
	Hante Meuleman <hante.meuleman@broadcom.com>,
	Chi-Hsien Lin <chi-hsien.lin@cypress.com>,
	Wright Feng <wright.feng@cypress.com>,
	Kalle Valo <kvalo@codeaurora.org>,
	"David S . Miller" <davem@davemloft.net>,
	linux-wireless@vger.kernel.org,
	brcm80211-dev-list.pdl@broadcom.com,
	brcm80211-dev-list@cypress.com, netdev@vger.kernel.org,
	kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][V2] brcmfmac: fix leak of mypkt on error return path
Date: Tue, 09 Apr 2019 11:55:44 +0000	[thread overview]
Message-ID: <20190409115544.GC6095@kadam> (raw)
In-Reply-To: <e0d984a7-6a6d-b902-6f75-26ee6f530efe@broadcom.com>

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

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Arend Van Spriel <arend.vanspriel@broadcom.com>
Cc: Colin King <colin.king@canonical.com>,
	Franky Lin <franky.lin@broadcom.com>,
	Hante Meuleman <hante.meuleman@broadcom.com>,
	Chi-Hsien Lin <chi-hsien.lin@cypress.com>,
	Wright Feng <wright.feng@cypress.com>,
	Kalle Valo <kvalo@codeaurora.org>,
	"David S . Miller" <davem@davemloft.net>,
	linux-wireless@vger.kernel.org,
	brcm80211-dev-list.pdl@broadcom.com,
	brcm80211-dev-list@cypress.com, netdev@vger.kernel.org,
	kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][V2] brcmfmac: fix leak of mypkt on error return path
Date: Tue, 9 Apr 2019 14:55:44 +0300	[thread overview]
Message-ID: <20190409115544.GC6095@kadam> (raw)
In-Reply-To: <e0d984a7-6a6d-b902-6f75-26ee6f530efe@broadcom.com>

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


  reply	other threads:[~2019-04-09 11:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09 11:43 [PATCH][V2] brcmfmac: fix leak of mypkt on error return path Colin King
2019-04-09 11:43 ` Colin King
2019-04-09 11:50 ` Arend Van Spriel
2019-04-09 11:50   ` Arend Van Spriel
2019-04-09 11:55   ` Dan Carpenter [this message]
2019-04-09 11:55     ` Dan Carpenter
2019-04-10  9:17 ` Sergei Shtylyov
2019-04-10  9:17   ` Sergei Shtylyov
2019-04-10  9:32 ` Mukesh Ojha
2019-04-10  9:44   ` Mukesh Ojha
2019-04-13 11:08 ` Kalle Valo
2019-04-13 11:08   ` Kalle Valo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190409115544.GC6095@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=arend.vanspriel@broadcom.com \
    --cc=brcm80211-dev-list.pdl@broadcom.com \
    --cc=brcm80211-dev-list@cypress.com \
    --cc=chi-hsien.lin@cypress.com \
    --cc=colin.king@canonical.com \
    --cc=davem@davemloft.net \
    --cc=franky.lin@broadcom.com \
    --cc=hante.meuleman@broadcom.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=wright.feng@cypress.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.