All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] wifi: mac80211: avoid u32_encode_bits() warning
@ 2023-02-14 13:20 Arnd Bergmann
  2023-02-14 17:21 ` Alexander Lobakin
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2023-02-14 13:20 UTC (permalink / raw)
  To: Johannes Berg, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Arnd Bergmann, Felix Fietkau, Alexander Wetzel,
	Toke Høiland-Jørgensen, Andrei Otcheretianski,
	linux-wireless, netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

gcc-9 triggers a false-postive warning in ieee80211_mlo_multicast_tx()
for u32_encode_bits(ffs(links) - 1, ...), since ffs() can return zero
on an empty bitmask, and the negative argument to u32_encode_bits()
is then out of range:

In file included from include/linux/ieee80211.h:21,
                 from include/net/cfg80211.h:23,
                 from net/mac80211/tx.c:23:
In function 'u32_encode_bits',
    inlined from 'ieee80211_mlo_multicast_tx' at net/mac80211/tx.c:4437:17,
    inlined from 'ieee80211_subif_start_xmit' at net/mac80211/tx.c:4485:3:
include/linux/bitfield.h:177:3: error: call to '__field_overflow' declared with attribute error: value doesn't fit into mask
  177 |   __field_overflow();     \
      |   ^~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:197:2: note: in expansion of macro '____MAKE_OP'
  197 |  ____MAKE_OP(u##size,u##size,,)
      |  ^~~~~~~~~~~
include/linux/bitfield.h:200:1: note: in expansion of macro '__MAKE_OP'
  200 | __MAKE_OP(32)
      | ^~~~~~~~~

Newer compiler versions do not cause problems with the zero argument
because they do not consider this a __builtin_constant_p().
It's also harmless since the hweight16() check already guarantees
that this cannot be 0.

Replace the ffs() with an equivalent find_first_bit() check that
matches the later for_each_set_bit() style and avoids the warning.

Fixes: 963d0e8d08d9 ("wifi: mac80211: optionally implement MLO multicast TX")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 net/mac80211/tx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index defe97a31724..118648af979c 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -4434,7 +4434,7 @@ static void ieee80211_mlo_multicast_tx(struct net_device *dev,
 	u32 ctrl_flags = IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX;
 
 	if (hweight16(links) == 1) {
-		ctrl_flags |= u32_encode_bits(ffs(links) - 1,
+		ctrl_flags |= u32_encode_bits(find_first_bit(&links, 16) - 1,
 					      IEEE80211_TX_CTRL_MLO_LINK);
 
 		__ieee80211_subif_start_xmit(skb, sdata->dev, 0, ctrl_flags,
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] wifi: mac80211: avoid u32_encode_bits() warning
  2023-02-14 13:20 [PATCH] wifi: mac80211: avoid u32_encode_bits() warning Arnd Bergmann
@ 2023-02-14 17:21 ` Alexander Lobakin
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Lobakin @ 2023-02-14 17:21 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Johannes Berg, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Arnd Bergmann, Felix Fietkau, Alexander Wetzel,
	Toke Høiland-Jørgensen, Andrei Otcheretianski,
	linux-wireless, netdev, linux-kernel

From: Arnd Bergmann <arnd@kernel.org>
Date: Tue, 14 Feb 2023 14:20:21 +0100

> From: Arnd Bergmann <arnd@arndb.de>
> 
> gcc-9 triggers a false-postive warning in ieee80211_mlo_multicast_tx()
> for u32_encode_bits(ffs(links) - 1, ...), since ffs() can return zero
> on an empty bitmask, and the negative argument to u32_encode_bits()
> is then out of range:
> 
> In file included from include/linux/ieee80211.h:21,
>                  from include/net/cfg80211.h:23,
>                  from net/mac80211/tx.c:23:
> In function 'u32_encode_bits',
>     inlined from 'ieee80211_mlo_multicast_tx' at net/mac80211/tx.c:4437:17,
>     inlined from 'ieee80211_subif_start_xmit' at net/mac80211/tx.c:4485:3:
> include/linux/bitfield.h:177:3: error: call to '__field_overflow' declared with attribute error: value doesn't fit into mask
>   177 |   __field_overflow();     \
>       |   ^~~~~~~~~~~~~~~~~~
> include/linux/bitfield.h:197:2: note: in expansion of macro '____MAKE_OP'
>   197 |  ____MAKE_OP(u##size,u##size,,)
>       |  ^~~~~~~~~~~
> include/linux/bitfield.h:200:1: note: in expansion of macro '__MAKE_OP'
>   200 | __MAKE_OP(32)
>       | ^~~~~~~~~
> 
> Newer compiler versions do not cause problems with the zero argument
> because they do not consider this a __builtin_constant_p().
> It's also harmless since the hweight16() check already guarantees
> that this cannot be 0.
> 
> Replace the ffs() with an equivalent find_first_bit() check that
> matches the later for_each_set_bit() style and avoids the warning.
> 
> Fixes: 963d0e8d08d9 ("wifi: mac80211: optionally implement MLO multicast TX")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  net/mac80211/tx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
> index defe97a31724..118648af979c 100644
> --- a/net/mac80211/tx.c
> +++ b/net/mac80211/tx.c
> @@ -4434,7 +4434,7 @@ static void ieee80211_mlo_multicast_tx(struct net_device *dev,
>  	u32 ctrl_flags = IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX;
>  
>  	if (hweight16(links) == 1) {
> -		ctrl_flags |= u32_encode_bits(ffs(links) - 1,
> +		ctrl_flags |= u32_encode_bits(find_first_bit(&links, 16) - 1,

Uff, IIRC find_first_bit() matches __ffs() calling convention, not ffs()
one. They're off-by-one from each other, which means you need to drop
this `- 1`.
As this branch happens only when hweight is 1 => @links has a bit set,
it's safe to just use __ffs() here directly, but up to you.
find_first_bit() is fine, too, since it will be optimized out to __ffs()
at the end in this case.

>  					      IEEE80211_TX_CTRL_MLO_LINK);
>  
>  		__ieee80211_subif_start_xmit(skb, sdata->dev, 0, ctrl_flags,
Thanks,
Olek

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-14 17:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 13:20 [PATCH] wifi: mac80211: avoid u32_encode_bits() warning Arnd Bergmann
2023-02-14 17:21 ` Alexander Lobakin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.