@@ -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;
}
}
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(-)