[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <02f0a505b3a02a3c5e29ac1e327acd1fc946188c.camel@realtek.com>
Date: Fri, 24 Nov 2023 11:19:23 +0000
From: Ping-Ke Shih <pkshih@...ltek.com>
To: "kvalo@...nel.org" <kvalo@...nel.org>,
"nathan@...nel.org" <nathan@...nel.org>,
"ndesaulniers@...gle.com" <ndesaulniers@...gle.com>,
"suhui@...china.com" <suhui@...china.com>,
"dan.carpenter@...aro.org" <dan.carpenter@...aro.org>,
"trix@...hat.com" <trix@...hat.com>
CC: "linux-wireless@...r.kernel.org" <linux-wireless@...r.kernel.org>,
"kernel-janitors@...r.kernel.org" <kernel-janitors@...r.kernel.org>,
"Larry.Finger@...inger.net" <Larry.Finger@...inger.net>,
"llvm@...ts.linux.dev" <llvm@...ts.linux.dev>,
"linville@...driver.com" <linville@...driver.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"lizetao1@...wei.com" <lizetao1@...wei.com>
Subject: Re: [PATCH v2 2/2] wifi: rtlwifi: rtl8821ae: phy: fix an undefined bitwise shift behavior
On Fri, 2023-11-24 at 18:06 +0800, Su Hui wrote:
>
> On 2023/11/24 16:51, Ping-Ke Shih wrote:
> > Subject: [PATCH v2 2/2] wifi: rtlwifi: rtl8821ae: phy: fix an undefined bitwise shift behavior
> >
> > [...]
> > > diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> > > b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> > > index 6df270e29e66..52ab1b0761c0 100644
> > > --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> > > +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> > > @@ -31,7 +31,12 @@ static u32 _rtl8821ae_phy_calculate_bit_shift(u32 bitmask)
> > > {
> > > u32 i = ffs(bitmask);
> > >
> > > - return i ? i - 1 : 32;
> > > + if (!i) {
> > > + WARN_ON_ONCE(1);
> > > + return 0;
> > > + }
> > > +
> > > + return i - 1;
> > > }
> > Personally, I prefer to use __ffs(), because in normal case no need additional '-1',
> > and abnormal cases should not happen.
>
> Hi, Ping-Ke
>
> Replace _rtl8821ae_phy_calculate_bit_shift() by __ffs(bitmask) is better,
> but I'm not sure what callers should do when callers check bitmask is 0 before calling.
> Maybe this check is useless?
>
> I can send a v3 patch if using __ffs(bitmask) and no check for bitmask is fine.
> Or could you send this patch if you have a better idea?
> Thanks for your suggestion!
>
Can this work to you?
static u32 _rtl8821ae_phy_calculate_bit_shift(u32 bitmask)
{
if (WARN_ON_ONCE(!bitmask))
return 0;
return __ffs(bitmask);
}
Powered by blists - more mailing lists