Skip to content

Commit 2adc6ed

Browse files
ecree-solarflaredavem330
authored andcommitted
ethtool: fix error handling in ethtool_phys_id
If ops->set_phys_id() returned an error, previously we would only break out of the inner loop, which neither stopped the outer loop nor returned the error to the user (since 'rc' would be overwritten on the next pass through the loop). Thus, rewrite it to use a single loop, so that the break does the right thing. Use u64 for 'count' and 'i' to prevent overflow in case of (unreasonably) large values of id.data and n. Signed-off-by: Edward Cree <ecree@solarflare.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 30ae801 commit 2adc6ed

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

‎net/ethtool/ioctl.c‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,23 +1861,18 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
18611861
id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
18621862
} else {
18631863
/* Driver expects to be called at twice the frequency in rc */
1864-
int n = rc * 2, i, interval = HZ / n;
1864+
int n = rc * 2, interval = HZ / n;
1865+
u64 count = n * id.data, i = 0;
18651866

1866-
/* Count down seconds */
18671867
do {
1868-
/* Count down iterations per second */
1869-
i = n;
1870-
do {
1871-
rtnl_lock();
1872-
rc = ops->set_phys_id(dev,
1873-
(i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1874-
rtnl_unlock();
1875-
if (rc)
1876-
break;
1877-
schedule_timeout_interruptible(interval);
1878-
} while (!signal_pending(current) && --i != 0);
1879-
} while (!signal_pending(current) &&
1880-
(id.data == 0 || --id.data != 0));
1868+
rtnl_lock();
1869+
rc = ops->set_phys_id(dev,
1870+
(i++ & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1871+
rtnl_unlock();
1872+
if (rc)
1873+
break;
1874+
schedule_timeout_interruptible(interval);
1875+
} while (!signal_pending(current) && (!id.data || i < count));
18811876
}
18821877

18831878
rtnl_lock();

0 commit comments

Comments
 (0)