All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Dewar <alex.dewar90@gmail.com>
To: Kalle Valo <kvalo@codeaurora.org>
Cc: Alex Dewar <alex.dewar90@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, Carl Huang <cjhuang@codeaurora.org>,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jakub Kicinski <kuba@kernel.org>,
	ath11k@lists.infradead.org
Subject: Re: [PATCH 2/2] ath11k: Handle errors if peer creation fails
Date: Tue, 6 Oct 2020 09:13:21 +0100	[thread overview]
Message-ID: <20201006081321.e2tf5xrdhnk4j3nq@medion> (raw)
In-Reply-To: <87blhfbysb.fsf@codeaurora.org>

On Tue, Oct 06, 2020 at 10:26:28AM +0300, Kalle Valo wrote:
> Alex Dewar <alex.dewar90@gmail.com> writes:
> 
> > ath11k_peer_create() is called without its return value being checked,
> > meaning errors will be unhandled. Add missing check and, as the mutex is
> > unconditionally unlocked on leaving this function, simplify the exit
> > path.
> >
> > Addresses-Coverity-ID: 1497531 ("Code maintainability issues")
> > Fixes: 701e48a43e15 ("ath11k: add packet log support for QCA6390")
> > Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
> > ---
> >  drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++------------
> >  1 file changed, 9 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
> > index 7f8dd47d2333..58db1b57b941 100644
> > --- a/drivers/net/wireless/ath/ath11k/mac.c
> > +++ b/drivers/net/wireless/ath/ath11k/mac.c
> > @@ -5211,7 +5211,7 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
> >  	struct ath11k *ar = hw->priv;
> >  	struct ath11k_base *ab = ar->ab;
> >  	struct ath11k_vif *arvif = (void *)vif->drv_priv;
> > -	int ret;
> > +	int ret = 0;
> 
> I prefer not to initialise the ret variable.
> 
> >  	arvif->is_started = true;
> >  
> >  	/* TODO: Setup ps and cts/rts protection */
> >  
> > -	mutex_unlock(&ar->conf_mutex);
> > -
> > -	return 0;
> > -
> > -err:
> > +unlock:
> >  	mutex_unlock(&ar->conf_mutex);
> >  
> >  	return ret;
> 
> So in the pending branch I changed this to:
> 
> 	ret = 0;
> 
> out:
> 	mutex_unlock(&ar->conf_mutex);
> 
> 	return ret;
> 
> Please check.

Hi Kalle,

I'm afraid you've introduced a bug ;). The body of the first if-statement
in the function doesn't set ret because no error has occurred. So now
it'll jump to the label and the function will return ret uninitialized.

With the gcc extension, ret will be initialised to zero anyway, so we're
not saving anything by explicitly assigning to ret later in the
function.

Best,
Alex

> 
> -- 
> https://patchwork.kernel.org/project/linux-wireless/list/
> 
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

WARNING: multiple messages have this Message-ID (diff)
From: Alex Dewar <alex.dewar90@gmail.com>
To: Kalle Valo <kvalo@codeaurora.org>
Cc: netdev@vger.kernel.org, Carl Huang <cjhuang@codeaurora.org>,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	ath11k@lists.infradead.org, Jakub Kicinski <kuba@kernel.org>,
	Alex Dewar <alex.dewar90@gmail.com>
Subject: Re: [PATCH 2/2] ath11k: Handle errors if peer creation fails
Date: Tue, 6 Oct 2020 09:13:21 +0100	[thread overview]
Message-ID: <20201006081321.e2tf5xrdhnk4j3nq@medion> (raw)
In-Reply-To: <87blhfbysb.fsf@codeaurora.org>

On Tue, Oct 06, 2020 at 10:26:28AM +0300, Kalle Valo wrote:
> Alex Dewar <alex.dewar90@gmail.com> writes:
> 
> > ath11k_peer_create() is called without its return value being checked,
> > meaning errors will be unhandled. Add missing check and, as the mutex is
> > unconditionally unlocked on leaving this function, simplify the exit
> > path.
> >
> > Addresses-Coverity-ID: 1497531 ("Code maintainability issues")
> > Fixes: 701e48a43e15 ("ath11k: add packet log support for QCA6390")
> > Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
> > ---
> >  drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++------------
> >  1 file changed, 9 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
> > index 7f8dd47d2333..58db1b57b941 100644
> > --- a/drivers/net/wireless/ath/ath11k/mac.c
> > +++ b/drivers/net/wireless/ath/ath11k/mac.c
> > @@ -5211,7 +5211,7 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
> >  	struct ath11k *ar = hw->priv;
> >  	struct ath11k_base *ab = ar->ab;
> >  	struct ath11k_vif *arvif = (void *)vif->drv_priv;
> > -	int ret;
> > +	int ret = 0;
> 
> I prefer not to initialise the ret variable.
> 
> >  	arvif->is_started = true;
> >  
> >  	/* TODO: Setup ps and cts/rts protection */
> >  
> > -	mutex_unlock(&ar->conf_mutex);
> > -
> > -	return 0;
> > -
> > -err:
> > +unlock:
> >  	mutex_unlock(&ar->conf_mutex);
> >  
> >  	return ret;
> 
> So in the pending branch I changed this to:
> 
> 	ret = 0;
> 
> out:
> 	mutex_unlock(&ar->conf_mutex);
> 
> 	return ret;
> 
> Please check.

Hi Kalle,

I'm afraid you've introduced a bug ;). The body of the first if-statement
in the function doesn't set ret because no error has occurred. So now
it'll jump to the label and the function will return ret uninitialized.

With the gcc extension, ret will be initialised to zero anyway, so we're
not saving anything by explicitly assigning to ret later in the
function.

Best,
Alex

> 
> -- 
> https://patchwork.kernel.org/project/linux-wireless/list/
> 
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

-- 
ath11k mailing list
ath11k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath11k

  reply	other threads:[~2020-10-06  8:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-04 10:02 [PATCH 2/2] ath11k: Handle errors if peer creation fails Alex Dewar
2020-10-04 10:02 ` Alex Dewar
2020-10-04 10:02 ` [PATCH 1/2] ath11k: Fix memory leak on error path Alex Dewar
2020-10-04 10:02   ` Alex Dewar
2020-10-08 10:46   ` Kalle Valo
2020-10-08 10:46   ` Kalle Valo
2020-10-06  7:26 ` [PATCH 2/2] ath11k: Handle errors if peer creation fails Kalle Valo
2020-10-06  7:26   ` Kalle Valo
2020-10-06  8:13   ` Alex Dewar [this message]
2020-10-06  8:13     ` Alex Dewar
2020-11-07 11:23     ` Kalle Valo
2020-11-07 11:23       ` Kalle Valo
2020-11-07 13:49       ` Alex Dewar
2020-11-07 13:49         ` Alex Dewar
2020-11-10 18:14 ` Kalle Valo
2020-11-10 18:15 ` 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=20201006081321.e2tf5xrdhnk4j3nq@medion \
    --to=alex.dewar90@gmail.com \
    --cc=ath11k@lists.infradead.org \
    --cc=cjhuang@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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.