mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Lachlan Hodges <lachlan.hodges@morsemicro.com>,
	Dan Callaghan <dan.callaghan@morsemicro.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	Arien Judge <arien.judge@morsemicro.com>,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Yury Norov <ynorov@nvidia.com>, Yury Norov <yury.norov@gmail.com>
Subject: [PATCH 1/2] wifi: morsemicro: mm81x: switch to use fns()
Date: Fri, 25 Sep 2026 15:59:07 -0400	[thread overview]
Message-ID: <20260925195908.252810-2-ynorov@nvidia.com> (raw)
In-Reply-To: <20260925195908.252810-1-ynorov@nvidia.com>

Replace the local nth_bit() helper with fns(), which provides the same
zero-based set-bit selection for rate capability masks.

Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
 drivers/net/wireless/morsemicro/mm81x/mmrc.c | 26 +++++---------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/drivers/net/wireless/morsemicro/mm81x/mmrc.c b/drivers/net/wireless/morsemicro/mm81x/mmrc.c
index fe7e4f501d6c..4cbc35535e07 100644
--- a/drivers/net/wireless/morsemicro/mm81x/mmrc.c
+++ b/drivers/net/wireless/morsemicro/mm81x/mmrc.c
@@ -2,6 +2,8 @@
 /*
  * Copyright (c) 2017-2026 Morse Micro
  */
+#include <linux/bitops.h>
+
 #include "mmrc.h"
 
 /*
@@ -198,22 +200,6 @@
  */
 static const u32 sym_table[10] = { 24, 36, 48, 72, 96, 144, 192, 216, 256, 288 };
 
-/*
- * Calculate which bit is the nth bit set in an integer based flag.
- */
-static u8 nth_bit(u16 in, u16 index)
-{
-	u32 i;
-	u8 count = 0;
-
-	for (i = 0; count != index + 1; i++) {
-		if (((1u << i) & in) != 0)
-			count++;
-	}
-
-	return i - 1;
-}
-
 /*
  * Calculate the input bit's index among all the set bits in an integer
  * based flag.
@@ -291,19 +277,19 @@ static struct mmrc_rate get_rate_row(struct mmrc_table *tb, u16 index)
 	u16 mcs_index = index / rows;
 	u16 mcs_modulo = index % rows;
 
-	mcs = nth_bit(tb->caps.rates, mcs_index);
+	mcs = fns(tb->caps.rates, mcs_index);
 
 	/* Find our spatial stream */
 	rows = rows / streams;
-	streams = nth_bit(tb->caps.spatial_streams, mcs_modulo / rows);
+	streams = fns(tb->caps.spatial_streams, mcs_modulo / rows);
 
 	/* Find our bandwidth */
 	ss_index = index % rows;
 	rows = rows / bw;
-	bw = nth_bit(tb->caps.bandwidth, ss_index / rows);
+	bw = fns(tb->caps.bandwidth, ss_index / rows);
 
 	/* Find our guard */
-	guard = nth_bit(tb->caps.guard, index % guard);
+	guard = fns(tb->caps.guard, index % guard);
 
 	/* Add range checks to keep scan-build happy */
 	if (bw >= MMRC_BW_MAX)
-- 
2.53.0


  reply	other threads:[~2026-09-25 19:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 19:59 [PATCH 0/2] wifi: morsemicro: mm81x: get rid of code duplications Yury Norov
2026-09-25 19:59 ` Yury Norov [this message]
2026-09-25 19:59 ` [PATCH 2/2] wifi: morsemicro: mm81x: use hweight16() to calculate bit index Yury Norov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260925195908.252810-2-ynorov@nvidia.com \
    --to=ynorov@nvidia.com \
    --cc=arien.judge@morsemicro.com \
    --cc=dan.callaghan@morsemicro.com \
    --cc=johannes@sipsolutions.net \
    --cc=lachlan.hodges@morsemicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®