netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ethtool: Fix and optimize ethtool_convert_link_mode_to_legacy_u32()
@ 2022-05-24 22:38 Marco Bonelli
  2022-05-24 23:21 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Marco Bonelli @ 2022-05-24 22:38 UTC (permalink / raw)
  To: netdev
  Cc: Marco Bonelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel

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: Marco Bonelli <marco@mebeim.net>
---
 net/ethtool/ioctl.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 326e14ee05db..7fb3f3fd6f3c 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -369,22 +369,9 @@ EXPORT_SYMBOL(ethtool_convert_legacy_u32_to_link_mode);
 bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
 					     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];
-	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);
 
-- 
2.30.2


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

* Re: [PATCH] ethtool: Fix and optimize ethtool_convert_link_mode_to_legacy_u32()
  2022-05-24 22:38 [PATCH] ethtool: Fix and optimize ethtool_convert_link_mode_to_legacy_u32() Marco Bonelli
@ 2022-05-24 23:21 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2022-05-24 23:21 UTC (permalink / raw)
  To: Marco Bonelli
  Cc: netdev, David S. Miller, Eric Dumazet, Paolo Abeni, linux-kernel

On Wed, 25 May 2022 00:38:19 +0200 Marco Bonelli wrote:
> 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: Marco Bonelli <marco@mebeim.net>

# Form letter - net-next is closed

We have already sent the networking pull request for 5.19
and therefore net-next is closed for new drivers, features,
code refactoring and optimizations. We are currently accepting
bug fixes only.

Please repost when net-next reopens after 5.19-rc1 is cut.

RFC patches sent for review only are obviously welcome at any time.

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

end of thread, other threads:[~2022-05-24 23:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24 22:38 [PATCH] ethtool: Fix and optimize ethtool_convert_link_mode_to_legacy_u32() Marco Bonelli
2022-05-24 23:21 ` Jakub Kicinski

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).