2023-12-19 06:59:40

by Su Hui

[permalink] [raw]
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 <[email protected]>
---
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
--
2.30.2



2023-12-20 06:48:11

by Ping-Ke Shih

[permalink] [raw]
Subject: RE: [PATCH wireless-next 01/11] wifi: rtlwifi: add calculate_bit_shift()



> -----Original Message-----
> From: Su Hui <[email protected]>
> Sent: Tuesday, December 19, 2023 2:57 PM
> To: Ping-Ke Shih <[email protected]>; [email protected]
> Cc: Su Hui <[email protected]>; [email protected]; [email protected];
> [email protected]
> 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 <[email protected]>

Acked-by: Ping-Ke Shih <[email protected]>

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