Message ID | 20231219065739.1895666-2-suhui@nfschina.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 52221dfddbbfb5b4e029bb2efe9bb7da33ec1e46 |
Delegated to: | Kalle Valo |
Headers | show |
Series | using calculate_bit_shift() to fix undefined bitwise shift behavior. | expand |
> -----Original Message----- > From: Su Hui <suhui@nfschina.com> > Sent: Tuesday, December 19, 2023 2:57 PM > To: Ping-Ke Shih <pkshih@realtek.com>; kvalo@kernel.org > Cc: Su Hui <suhui@nfschina.com>; linux-wireless@vger.kernel.org; linux-kernel@vger.kernel.org; > kernel-janitors@vger.kernel.org > Subject: [PATCH wireless-next 01/11] wifi: rtlwifi: add calculate_bit_shift() > > There are many same functions like _rtl88e_phy_calculate_bit_shift(), > _rtl92c_phy_calculate_bit_shift() and so on. And these functions can > cause undefined bitwise shift behavior. Add calculate_bit_shift() to > replace them and fix undefined behavior in subsequent patches. > > Signed-off-by: Su Hui <suhui@nfschina.com> Acked-by: Ping-Ke Shih <pkshih@realtek.com> > --- > drivers/net/wireless/realtek/rtlwifi/wifi.h | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h b/drivers/net/wireless/realtek/rtlwifi/wifi.h > index 31a481f43a07..5d842cc394aa 100644 > --- a/drivers/net/wireless/realtek/rtlwifi/wifi.h > +++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h > @@ -3069,4 +3069,11 @@ static inline struct ieee80211_sta *rtl_find_sta(struct ieee80211_hw *hw, > return ieee80211_find_sta(mac->vif, mac_addr); > } > > +static inline u32 calculate_bit_shift(u32 bitmask) > +{ > + if (WARN_ON_ONCE(!bitmask)) > + return 0; > + > + return __ffs(bitmask); > +} > #endif Basically, this patchset is to change from below example to above one. static u32 _rtl92d_phy_calculate_bit_shift(u32 bitmask) { u32 i = ffs(bitmask); return i ? i - 1 : 32; } And, bitmask is expected not 0, so all are fine to me. (I don't reply all patches one-by-one to bother people) Ping-Ke
Su Hui <suhui@nfschina.com> wrote: > There are many same functions like _rtl88e_phy_calculate_bit_shift(), > _rtl92c_phy_calculate_bit_shift() and so on. And these functions can > cause undefined bitwise shift behavior. Add calculate_bit_shift() to > replace them and fix undefined behavior in subsequent patches. > > Signed-off-by: Su Hui <suhui@nfschina.com> > Acked-by: Ping-Ke Shih <pkshih@realtek.com> 11 patches applied to wireless-next.git, thanks. 52221dfddbbf wifi: rtlwifi: add calculate_bit_shift() acefef7a7e7a wifi: rtlwifi: rtl8821ae: phy: using calculate_bit_shift() 969bc926f04b wifi: rtlwifi: rtl8188ee: phy: using calculate_bit_shift() 1dedc3a6699d wifi: rtlwifi: rtl8192c: using calculate_bit_shift() f4088c8fcbab wifi: rtlwifi: rtl8192cu: using calculate_bit_shift() 3d03e8231031 wifi: rtlwifi: rtl8192ce: using calculate_bit_shift() b8b2baad2e65 wifi: rtlwifi: rtl8192de: using calculate_bit_shift() 63526897fc0d wifi: rtlwifi: rtl8192ee: using calculate_bit_shift() ac32b9317063 wifi: rtlwifi: rtl8192se: using calculate_bit_shift() 98d9c7731dbb wifi: rtlwifi: rtl8723_common: using calculate_bit_shift() 5c16618bc06a wifi: rtlwifi: rtl8723{be,ae}: using calculate_bit_shift()
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h b/drivers/net/wireless/realtek/rtlwifi/wifi.h index 31a481f43a07..5d842cc394aa 100644 --- a/drivers/net/wireless/realtek/rtlwifi/wifi.h +++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h @@ -3069,4 +3069,11 @@ static inline struct ieee80211_sta *rtl_find_sta(struct ieee80211_hw *hw, return ieee80211_find_sta(mac->vif, mac_addr); } +static inline u32 calculate_bit_shift(u32 bitmask) +{ + if (WARN_ON_ONCE(!bitmask)) + return 0; + + return __ffs(bitmask); +} #endif
There are many same functions like _rtl88e_phy_calculate_bit_shift(), _rtl92c_phy_calculate_bit_shift() and so on. And these functions can cause undefined bitwise shift behavior. Add calculate_bit_shift() to replace them and fix undefined behavior in subsequent patches. Signed-off-by: Su Hui <suhui@nfschina.com> --- drivers/net/wireless/realtek/rtlwifi/wifi.h | 7 +++++++ 1 file changed, 7 insertions(+)