Skip to content

Commit

Permalink
ethtool: Return immediately on error in ethtool_copy_validate_indir()
Browse files Browse the repository at this point in the history
We must return -EFAULT immediately rather than continuing into
the loop.

Similarly, we may as well return -EINVAL directly.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
  • Loading branch information
bwhacks committed May 19, 2014
1 parent eb02a27 commit fb95cd8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions net/core/ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,19 +561,17 @@ static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
struct ethtool_rxnfc *rx_rings,
u32 size)
{
int ret = 0, i;
int i;

if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
ret = -EFAULT;
return -EFAULT;

/* Validate ring indices */
for (i = 0; i < size; i++) {
if (indir[i] >= rx_rings->data) {
ret = -EINVAL;
break;
}
}
return ret;
for (i = 0; i < size; i++)
if (indir[i] >= rx_rings->data)
return -EINVAL;

return 0;
}

static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
Expand Down

0 comments on commit fb95cd8

Please sign in to comment.