LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Larry Finger <Larry.Finger@lwfinger.net>
To: Colin King <colin.king@canonical.com>,
	Ping-Ke Shih <pkshih@realtek.com>,
	Kalle Valo <kvalo@codeaurora.org>,
	"David S . Miller" <davem@davemloft.net>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rtlwifi: remove redundant assignment to variable k
Date: Fri, 31 May 2019 12:29:12 -0500	[thread overview]
Message-ID: <14372bed-6522-d81c-7d68-04adc0d71193@lwfinger.net> (raw)
In-Reply-To: <20190531141412.18632-1-colin.king@canonical.com>

On 5/31/19 9:14 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The assignment of 0 to variable k is never read once we break out of
> the loop, so the assignment is redundant and can be removed.
> 
> Addresses-Coverity: ("Unused value")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   drivers/net/wireless/realtek/rtlwifi/efuse.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtlwifi/efuse.c b/drivers/net/wireless/realtek/rtlwifi/efuse.c
> index e68340dfd980..83e5318ca04f 100644
> --- a/drivers/net/wireless/realtek/rtlwifi/efuse.c
> +++ b/drivers/net/wireless/realtek/rtlwifi/efuse.c
> @@ -117,10 +117,8 @@ u8 efuse_read_1byte(struct ieee80211_hw *hw, u16 address)
>   						 rtlpriv->cfg->
>   						 maps[EFUSE_CTRL] + 3);
>   			k++;
> -			if (k == 1000) {
> -				k = 0;
> +			if (k == 1000)
>   				break;
> -			}
>   		}
>   		data = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
>   		return data;

Colin,

Your patch is not wrong, but it fails to address a basic deficiency of this code 
snippet - when an error is detected, there is no attempt to either fix the 
problem or report it upstream. As the data returned will be garbage if this 
condition happens, we might as well replace the "break" with "return 0xFF", as 
well as deleting the "k = 0" line. Most of the callers of efuse_read_1byte() 
ignore the returned result when bits 0 and 4 are set, thus returning all 8 bits 
is not a bad fixup.

My suspicion is that this test is in the code merely to prevent an potential 
unterminated "while" loop, and that this condition is extremely unlikely to happen.

Larry



  reply	other threads:[~2019-05-31 17:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31 14:14 Colin King
2019-05-31 17:29 ` Larry Finger [this message]
2019-05-31 19:41   ` Joe Perches
2019-06-25  5:00 ` 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=14372bed-6522-d81c-7d68-04adc0d71193@lwfinger.net \
    --to=larry.finger@lwfinger.net \
    --cc=colin.king@canonical.com \
    --cc=davem@davemloft.net \
    --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=pkshih@realtek.com \
    --subject='Re: [PATCH] rtlwifi: remove redundant assignment to variable k' \
    /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

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).