[PATCH net v2] eth: fbnic: Avoid rounding zero ring sizes

Björn Töpel posted 1 patch 6 days, 11 hours ago
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
[PATCH net v2] eth: fbnic: Avoid rounding zero ring sizes
Posted by Björn Töpel 6 days, 11 hours ago
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")
Reported-by: Sashiko <netdev-bot+sashiko@kernel.org>
Link: https://lore.kernel.org/netdev/178971206933.22033.236948278674126701@kernel.org/
Suggested-by: Alexander Duyck <alexanderduyck@fb.com>
Signed-off-by: Björn Töpel <bjorn@kernel.org>

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

diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c
index 0e47088ec44b..f68936e5558b 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c
@@ -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
-- 
2.55.0

Re: [PATCH net v2] eth: fbnic: Avoid rounding zero ring sizes
Posted by Joe Damato 5 days, 23 hours ago
On Fri, Sep 18, 2026 at 01:46:40PM +0200, Björn Töpel 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.
> 
> Fixes: 6cbf18a05c06 ("eth: fbnic: support ring size configuration")
> Reported-by: Sashiko <netdev-bot+sashiko@kernel.org>
> Link: https://lore.kernel.org/netdev/178971206933.22033.236948278674126701@kernel.org/
> Suggested-by: Alexander Duyck <alexanderduyck@fb.com>
> Signed-off-by: Björn Töpel <bjorn@kernel.org>
> 
> ---
> 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(-)

Reviewed-by: Joe Damato <joe@dama.to>