Skip to content

Commit 55b2433

Browse files
Ryceancurrykuba-moo
authored andcommitted
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 <[email protected]> Signed-off-by: Justin Chen <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 68bd67b commit 55b2433

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

net/ethtool/ioctl.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
14361436

14371437
static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
14381438
{
1439-
struct ethtool_wolinfo wol;
1439+
struct ethtool_wolinfo wol, cur_wol;
14401440
int ret;
14411441

1442-
if (!dev->ethtool_ops->set_wol)
1442+
if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol)
14431443
return -EOPNOTSUPP;
14441444

1445+
memset(&cur_wol, 0, sizeof(struct ethtool_wolinfo));
1446+
cur_wol.cmd = ETHTOOL_GWOL;
1447+
dev->ethtool_ops->get_wol(dev, &cur_wol);
1448+
14451449
if (copy_from_user(&wol, useraddr, sizeof(wol)))
14461450
return -EFAULT;
14471451

1452+
if (wol.wolopts & ~cur_wol.supported)
1453+
return -EINVAL;
1454+
1455+
if (wol.wolopts == cur_wol.wolopts)
1456+
return 0;
1457+
14481458
ret = dev->ethtool_ops->set_wol(dev, &wol);
14491459
if (ret)
14501460
return ret;

0 commit comments

Comments
 (0)