Skip to contentSkip to conversation

eth: fbnic: Avoid rounding zero ring sizes

PATCH Applied Björn Töpel 3 participants 3 messages Sep 18 – Sep 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 eth: fbnic: Avoid rounding zero ring sizes

roundup_pow_of_two() is undefined for zero. ethtool permits a zero ring size to reach the driver, where the minimum-size check should reject it.

Leave zero unchanged while rounding nonzero ring sizes. The minimum-size check then rejects zero deterministically without changing the established behavior for other values.

Fixes 6cbf18a05c06 ("eth: fbnic: support ring size configuration")

---
v2:
- Preserve rounding before minimum-size validation for nonzero values; Sashiko found that v1 rejected values which previously rounded up to a valid size.

---
 drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +9 -4
index 0e47088ec44b..f68936e5558b 100644
@@ -313,6 +313,11 @@ fbnic_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
 	kernel_ring->hds_thresh = fbn->hds_thresh;
 }
 
+static u32 fbnic_ring_size_pow2(u32 size)
+{
+	return size ? roundup_pow_of_two(size) : 0;
+}
+
 static void fbnic_set_rings(struct fbnic_net *fbn,
 			    struct ethtool_ringparam *ring,
 			    struct kernel_ethtool_ringparam *kernel_ring)
@@ -334,10 +339,10 @@ fbnic_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
 	struct fbnic_net *clone;
 	int err;
 
-	ring->rx_pending	= roundup_pow_of_two(ring->rx_pending);
-	ring->rx_mini_pending	= roundup_pow_of_two(ring->rx_mini_pending);
-	ring->rx_jumbo_pending	= roundup_pow_of_two(ring->rx_jumbo_pending);
-	ring->tx_pending	= roundup_pow_of_two(ring->tx_pending);
+	ring->rx_pending	= fbnic_ring_size_pow2(ring->rx_pending);
+	ring->rx_mini_pending	= fbnic_ring_size_pow2(ring->rx_mini_pending);
+	ring->rx_jumbo_pending	= fbnic_ring_size_pow2(ring->rx_jumbo_pending);
+	ring->tx_pending	= fbnic_ring_size_pow2(ring->tx_pending);
 
 	/* These are absolute minimums allowing the device and driver to operate
 	 * but not necessarily guarantee reasonable performance. Settings below

base-commit: 46bc52d13594848023e681860df8700c8db14354

Signature · 1 line
2.55.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · Björn Töpel

roundup_pow_of_two() is undefined for zero. ethtool permits a zero ring size to reach the driver, where the minimum-size check should reject it.

Leave zero unchanged while rounding nonzero ring sizes. The minimum-size check then rejects zero deterministically without changing the established behavior for other values.

Fixes 6cbf18a05c06 ("eth: fbnic: support ring size configuration")
Quoted 8 lines

---
v2:
- Preserve rounding before minimum-size validation for nonzero values; Sashiko found that v1 rejected values which previously rounded up to a valid size.

---
 drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
#2 lore raw
In reply to Björn Töpel
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Fri, 18 Sep 2026 13:46:40 +0200 you wrote:

roundup_pow_of_two() is undefined for zero. ethtool permits a zero ring size to reach the driver, where the minimum-size check should reject it.

Leave zero unchanged while rounding nonzero ring sizes. The minimum-size check then rejects zero deterministically without changing the established behavior for other values.

[...]

Here is the summary with links:
- [net,v2] eth: fbnic: Avoid rounding zero ring sizes

    https://git.kernel.org/netdev/net/c/0160953d8eec

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html