diff mbox series

[net-next,v1,2/2] ethtool: refactor bit-shifts

Message ID 20221207231728.2331166-3-jesse.brandeburg@intel.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series ethtool: use bits.h defines | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers warning 1 maintainers not CCed: edumazet@google.com
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 40 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jesse Brandeburg Dec. 7, 2022, 11:17 p.m. UTC
While coding up the BIT() conversions for ethtool, some ugly conversions
and code were noticed and we can fix them with a little GENMASK and a
small refactor to use local variables to simplify some bitset.c code.

These changes should have no functional effect.

Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 net/ethtool/bitset.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/net/ethtool/bitset.c b/net/ethtool/bitset.c
index 0515d6604b3b..ac289f335582 100644
--- a/net/ethtool/bitset.c
+++ b/net/ethtool/bitset.c
@@ -14,12 +14,12 @@ 
 
 static u32 ethnl_lower_bits(unsigned int n)
 {
-	return ~(u32)0 >> (32 - n % 32);
+	return GENMASK((n % 32), 0);
 }
 
 static u32 ethnl_upper_bits(unsigned int n)
 {
-	return ~(u32)0 << (n % 32);
+	return GENMASK(31, (n % 32));
 }
 
 /**
@@ -452,8 +452,8 @@  ethnl_update_bitset32_verbose(u32 *bitmap, unsigned int nbits,
 		ethnl_bitmap32_clear(bitmap, 0, nbits, mod);
 
 	nla_for_each_nested(bit_attr, tb[ETHTOOL_A_BITSET_BITS], rem) {
+		unsigned int idx, bitmap_idx, mod_idx;
 		bool old_val, new_val;
-		unsigned int idx;
 
 		if (nla_type(bit_attr) != ETHTOOL_A_BITSET_BITS_BIT) {
 			NL_SET_ERR_MSG_ATTR(extack, bit_attr,
@@ -464,12 +464,14 @@  ethnl_update_bitset32_verbose(u32 *bitmap, unsigned int nbits,
 				      names, extack);
 		if (ret < 0)
 			return ret;
-		old_val = bitmap[idx / 32] & ((u32)1 << (idx % 32));
+		bitmap_idx = idx / 32;
+		mod_idx = idx % 32;
+		old_val = bitmap[bitmap_idx] & BIT(mod_idx);
 		if (new_val != old_val) {
 			if (new_val)
-				bitmap[idx / 32] |= ((u32)1 << (idx % 32));
+				bitmap[bitmap_idx] |= BIT(mod_idx);
 			else
-				bitmap[idx / 32] &= ~((u32)1 << (idx % 32));
+				bitmap[bitmap_idx] &= ~BIT(mod_idx);
 			*mod = true;
 		}
 	}