Skip to contentSkip to conversation

ethtool: exit the loop when invalid index occurs

PATCH Applied Jean Sacren 2 participants 2 messages Apr 27, 2014 – Apr 28, 2014

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

PATCH 1/1 ethtool: exit the loop when invalid index occurs

The commit 3de0b592394d ("ethtool: Support for configurable RSS hash key") introduced a new function ethtool_copy_validate_indir() with full iteration of the loop to validate the ring indices, which could be an overkill. To minimize the impact, we ought to exit the loop as soon as the invalid index occurs for the very first time. The remaining loop simply doesn't serve any more purpose.

Cc Venkata Duvvuru <[email protected]>
---
 net/core/ethtool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/ethtool.c +3 -1
index 1d72786ef866..aa8978ac47d2 100644
@@ -568,8 +568,10 @@ static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
 
 	/* Validate ring indices */
 	for (i = 0; i < size; i++) {
-		if (indir[i] >= rx_rings->data)
+		if (indir[i] >= rx_rings->data) {
 			ret = -EINVAL;
+			break;
+		}
 	}
 	return ret;
 }
maintainer Applied
#1 lore raw

From: Jean Sacren <[email protected]>
Date: Sun, 27 Apr 2014 02:20:38 -0600

Quoted 9 lines

The commit 3de0b592394d ("ethtool: Support for configurable RSS hash key") introduced a new function ethtool_copy_validate_indir() with full iteration of the loop to validate the ring indices, which could be an overkill. To minimize the impact, we ought to exit the loop as soon as the invalid index occurs for the very first time. The remaining loop simply doesn't serve any more purpose.

Cc Venkata Duvvuru <[email protected]>

Applied.