Commit 19d62f5e authored by Marco Bonelli's avatar Marco Bonelli Committed by Jakub Kicinski

ethtool: Fix and simplify ethtool_convert_link_mode_to_legacy_u32()

Fix the implementation of ethtool_convert_link_mode_to_legacy_u32(), which
is supposed to return false if src has bits higher than 31 set. The current
implementation uses the complement of bitmap_fill(ext, 32) to test high
bits of src, which is wrong as bitmap_fill() fills _with long granularity_,
and sizeof(long) can be > 4. No users of this function currently check the
return value, so the bug was dormant.

Also remove the check for __ETHTOOL_LINK_MODE_MASK_NBITS > 32, as the enum
ethtool_link_mode_bit_indices contains far beyond 32 values. Using
find_next_bit() to test the src bitmask works regardless of this anyway.
Signed-off-by: default avatarMarco Bonelli <marco@mebeim.net>
Link: https://lore.kernel.org/r/20220609134900.11201-1-marco@mebeim.netSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent bfa54812
...@@ -369,22 +369,9 @@ EXPORT_SYMBOL(ethtool_convert_legacy_u32_to_link_mode); ...@@ -369,22 +369,9 @@ EXPORT_SYMBOL(ethtool_convert_legacy_u32_to_link_mode);
bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32, bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
const unsigned long *src) const unsigned long *src)
{ {
bool retval = true;
/* TODO: following test will soon always be true */
if (__ETHTOOL_LINK_MODE_MASK_NBITS > 32) {
__ETHTOOL_DECLARE_LINK_MODE_MASK(ext);
linkmode_zero(ext);
bitmap_fill(ext, 32);
bitmap_complement(ext, ext, __ETHTOOL_LINK_MODE_MASK_NBITS);
if (linkmode_intersects(ext, src)) {
/* src mask goes beyond bit 31 */
retval = false;
}
}
*legacy_u32 = src[0]; *legacy_u32 = src[0];
return retval; return find_next_bit(src, __ETHTOOL_LINK_MODE_MASK_NBITS, 32) ==
__ETHTOOL_LINK_MODE_MASK_NBITS;
} }
EXPORT_SYMBOL(ethtool_convert_link_mode_to_legacy_u32); EXPORT_SYMBOL(ethtool_convert_link_mode_to_legacy_u32);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment