linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] mac80211: improve the contiguous mask checking
@ 2015-12-17 14:59 Zeng Zhaoxiu
  2015-12-17 15:04 ` Johannes Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Zeng Zhaoxiu @ 2015-12-17 14:59 UTC (permalink / raw)
  To: johannes, davem; +Cc: linux-wireless, netdev, linux-kernel, Zeng Zhaoxiu

If the result of adding the first set bit to the mask is power of 2,
the mask must be contiguous. "mask & -mask" can get the first set bit
of mask gracefully.

Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
---
 net/mac80211/iface.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index c9e325d..4c896e8 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1628,7 +1628,9 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
 			((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
 			((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
 
-		if (__ffs64(mask) + hweight64(mask) != fls64(mask)) {
+		inc = (mask & -mask);
+		val = mask + inc;
+		if ((val & (val - 1)) != 0) {
 			/* not a contiguous mask ... not handled now! */
 			pr_info("not contiguous\n");
 			break;
@@ -1649,7 +1651,6 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
 			((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
 			((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
 
-		inc = 1ULL<<__ffs64(mask);
 		val = (start & mask);
 		addr = (start & ~mask) | (val & mask);
 		do {
-- 
2.5.0


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

* Re: [PATCH 1/1] mac80211: improve the contiguous mask checking
  2015-12-17 14:59 [PATCH 1/1] mac80211: improve the contiguous mask checking Zeng Zhaoxiu
@ 2015-12-17 15:04 ` Johannes Berg
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Berg @ 2015-12-17 15:04 UTC (permalink / raw)
  To: Zeng Zhaoxiu, davem; +Cc: linux-wireless, netdev, linux-kernel

On Thu, 2015-12-17 at 22:59 +0800, Zeng Zhaoxiu wrote:
> If the result of adding the first set bit to the mask is power of 2,
> the mask must be contiguous. "mask & -mask" can get the first set bit
> of mask gracefully.

> -		if (__ffs64(mask) + hweight64(mask) != fls64(mask))
> {
> +		inc = (mask & -mask);
> +		val = mask + inc;
> +		if ((val & (val - 1)) != 0) {
>  			/* not a contiguous mask ... not handled now! */

Hm. Ok, I can see how that would work, but it doesn't really seem like
much of an "improvement" to me? Surely I seem to need much more
thinking to understand this. There's no reason to optimise it either,
so why should we change it?

johannes

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

end of thread, other threads:[~2015-12-17 15:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-17 14:59 [PATCH 1/1] mac80211: improve the contiguous mask checking Zeng Zhaoxiu
2015-12-17 15:04 ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).