[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <4ff3b088ef8b160dc2e878092c605e4481edb625.camel@intel.com>
Date: Wed, 17 Nov 2021 06:56:47 +0000
From: "Coelho, Luciano" <luciano.coelho@...el.com>
To: "joe@...ches.com" <joe@...ches.com>,
"cgel.zte@...il.com" <cgel.zte@...il.com>
CC: "zealci@....com.cn" <zealci@....com.cn>,
"kvalo@...eaurora.org" <kvalo@...eaurora.org>,
"Berg, Johannes" <johannes.berg@...el.com>,
"ye.guojin@....com.cn" <ye.guojin@....com.cn>,
"davem@...emloft.net" <davem@...emloft.net>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-wireless@...r.kernel.org" <linux-wireless@...r.kernel.org>,
"Korenblit, Miriam Rachel" <miriam.rachel.korenblit@...el.com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"kuba@...nel.org" <kuba@...nel.org>
Subject: Re: [PATCH] iwlwifi: rs: fixup the return value type of
iwl_legacy_rate_to_fw_idx()
On Tue, 2021-11-16 at 22:41 -0800, Joe Perches wrote:
> On Wed, 2021-11-17 at 06:36 +0000, cgel.zte@...il.com wrote:
> > From: Ye Guojin <ye.guojin@....com.cn>
> >
> > This was found by coccicheck:
> > ./drivers/net/wireless/intel/iwlwifi/fw/rs.c, 147, 10-21, WARNING
> > Unsigned expression compared with zero legacy_rate < 0
> []
> > diff --git a/drivers/net/wireless/intel/iwlwifi/fw/rs.c b/drivers/net/wireless/intel/iwlwifi/fw/rs.c
> []
> > @@ -142,7 +142,7 @@ u32 iwl_new_rate_from_v1(u32 rate_v1)
> > }
> > /* if legacy format */
> > } else {
> > - u32 legacy_rate = iwl_legacy_rate_to_fw_idx(rate_v1);
> > + int legacy_rate = iwl_legacy_rate_to_fw_idx(rate_v1);
> >
> > WARN_ON(legacy_rate < 0);
>
> Why not just remove the WARN_ON instead?
>
Well, iwl_legacy_rate_to_fw_idx() _tries_ to return -1 if we can't find
the index.
But there are a few more wrong things in this implementation:
1. the iwl_legacy_rate_to_fw_idx() function is only called inside the
fw/rs.c file, so it should be static;
2. if we don't find the idx and return -1, we WARN but still use the
value, which will cause the rate_v2 to be set to 0xffffffff, which I'm
pretty sure is not the intention.
So, this should be fixed properly, rather than just changing the
function to return int.
--
Cheers,
Luca.
Powered by blists - more mailing lists