All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: mlx4_en: report the actual RX classification rule count
@ 2026-11-21  0:14 Artemii Mashanov
  2026-11-21  0:17 ` netdev-bot+sinfo
  2026-11-21  0:23 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Artemii Mashanov @ 2026-11-21  0:14 UTC (permalink / raw)
  To: netdev
  Cc: Tariq Toukan, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-rdma

mlx4_en_get_rxnfc() treats the input rule_cnt as the number of
rules it needs to find for ETHTOOL_GRXCLSRLALL.

With room for four locations and only one rule installed, the
ioctl succeeds with rule_cnt still set to four and three extra
zero entries. When the buffer has too few slots, the ioctl
succeeds with an incomplete list.

Bound the scan by the rule table size, skip empty slots and
propagate unexpected lookup errors. Return -EMSGSIZE when the next
rule cannot fit and set rule_cnt to the number of copied locations
on success.

The source-extracted ASan/UBSan regression tests passed.

Fixes: 820672812f82 ("net/mlx4_en: Manage flow steering rules with ethtool")
Signed-off-by: Artemii Mashanov <ralerrdirsardx@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx4/en_ethtool.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
index 4ba1947..463c1a4 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
@@ -1739,8 +1739,9 @@ static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
 {
 	struct mlx4_en_priv *priv = netdev_priv(dev);
 	struct mlx4_en_dev *mdev = priv->mdev;
+	u32 count = 0;
 	int err = 0;
-	int i = 0, priority = 0;
+	int i;
 
 	if ((cmd->cmd == ETHTOOL_GRXCLSRLCNT ||
 	     cmd->cmd == ETHTOOL_GRXCLSRULE ||
@@ -1758,12 +1759,17 @@ static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
 		break;
 	case ETHTOOL_GRXCLSRLALL:
 		cmd->data = MAX_NUM_OF_FS_RULES;
-		while ((!err || err == -ENOENT) && priority < cmd->rule_cnt) {
+		for (i = 0; i < MAX_NUM_OF_FS_RULES; i++) {
 			err = mlx4_en_get_flow(dev, cmd, i);
-			if (!err)
-				rule_locs[priority++] = i;
-			i++;
+			if (err == -ENOENT)
+				continue;
+			if (err)
+				return err;
+			if (count == cmd->rule_cnt)
+				return -EMSGSIZE;
+			rule_locs[count++] = i;
 		}
+		cmd->rule_cnt = count;
 		err = 0;
 		break;
 	default:
-- 
2.56.0


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

end of thread, other threads:[~2026-11-21  0:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21  0:14 [PATCH net] net: mlx4_en: report the actual RX classification rule count Artemii Mashanov
2026-11-21  0:17 ` netdev-bot+sinfo
2026-11-21  0:23 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.