wifi: rtlwifi: add calculate_bit_shift()
authorSu Hui <suhui@nfschina.com>
Tue, 19 Dec 2023 06:57:29 +0000 (14:57 +0800)
committerKalle Valo <kvalo@kernel.org>
Thu, 21 Dec 2023 14:40:16 +0000 (16:40 +0200)
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>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20231219065739.1895666-2-suhui@nfschina.com
drivers/net/wireless/realtek/rtlwifi/wifi.h

index ac8dfda7099de7802e267bd3f946ef794e6e71aa..d87cd2252eac03e218a41d578850d00fcb6c6d25 100644 (file)
@@ -3052,4 +3052,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