ethtool: exit the loop when invalid index occurs
authorJean Sacren <sakiwit@gmail.com>
Sun, 27 Apr 2014 08:20:38 +0000 (02:20 -0600)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Apr 2014 17:28:43 +0000 (13:28 -0400)
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.

Signed-off-by: Jean Sacren <sakiwit@gmail.com>
Cc: Venkata Duvvuru <VenkatKumar.Duvvuru@Emulex.Com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/ethtool.c

index 1d72786ef866cc6ae728a60cf90d1a74793b7a74..aa8978ac47d28b8588ff78e02e9607b1d616d6d1 100644 (file)
@@ -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;
 }