From: Jean Sacren Date: Sun, 27 Apr 2014 08:20:38 +0000 (-0600) Subject: ethtool: exit the loop when invalid index occurs X-Git-Tag: submit/tizen/20160607.132125~4450^2~308 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=266a16468432a77f2e1395b3de5df3ca699b1a9a;p=sdk%2Femulator%2Femulator-kernel.git 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. Signed-off-by: Jean Sacren Cc: Venkata Duvvuru Signed-off-by: David S. Miller --- diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 1d72786ef866..aa8978ac47d2 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -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; }