Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ethtool: ioctl: improve error checking for set_wol

The netlink version of set_wol checks for not supported wolopts and avoids
setting wol when the correct wolopt is already set. If we do the same with
the ioctl version then we can remove these checks from the driver layer.

Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Justin Chen <justin.chen@broadcom.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Link: https://lore.kernel.org/r/1686179653-29750-1-git-send-email-justin.chen@broadcom.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Justin Chen and committed by
Jakub Kicinski
55b24334 68bd67b4

+12 -2
+12 -2
net/ethtool/ioctl.c
··· 1436 1436 1437 1437 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) 1438 1438 { 1439 - struct ethtool_wolinfo wol; 1439 + struct ethtool_wolinfo wol, cur_wol; 1440 1440 int ret; 1441 1441 1442 - if (!dev->ethtool_ops->set_wol) 1442 + if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol) 1443 1443 return -EOPNOTSUPP; 1444 + 1445 + memset(&cur_wol, 0, sizeof(struct ethtool_wolinfo)); 1446 + cur_wol.cmd = ETHTOOL_GWOL; 1447 + dev->ethtool_ops->get_wol(dev, &cur_wol); 1444 1448 1445 1449 if (copy_from_user(&wol, useraddr, sizeof(wol))) 1446 1450 return -EFAULT; 1451 + 1452 + if (wol.wolopts & ~cur_wol.supported) 1453 + return -EINVAL; 1454 + 1455 + if (wol.wolopts == cur_wol.wolopts) 1456 + return 0; 1447 1457 1448 1458 ret = dev->ethtool_ops->set_wol(dev, &wol); 1449 1459 if (ret)