Skip to contentSkip to conversation

ethtool: do not set some flags, if others failed

PATCH Applied Jeff Garzik 2 participants 2 messages Feb 27, 2010 – Feb 28, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ethtool: do not set some flags, if others failed

NETIF_F_NTUPLE flag setting introduced a bug: non-ntuple flags like LRO may be successfully set, before ioctl(2) returns failure to userspace.

The set-flags operation should be all-or-none, rather than leaving things in an inconsistent state prior to reporting failure to userspace.

---
 net/core/ethtool.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/core/ethtool.c +6 -4
index 31b1edd..0f2f821 100644
@@ -135,21 +135,23 @@ u32 ethtool_op_get_flags(struct net_device *dev)
 int ethtool_op_set_flags(struct net_device *dev, u32 data)
 {
 	const struct ethtool_ops *ops = dev->ethtool_ops;
+	unsigned long features = dev->features;
 
 	if (data & ETH_FLAG_LRO)
-		dev->features |= NETIF_F_LRO;
+		features |= NETIF_F_LRO;
 	else
-		dev->features &= ~NETIF_F_LRO;
+		features &= ~NETIF_F_LRO;
 
 	if (data & ETH_FLAG_NTUPLE) {
 		if (!ops->set_rx_ntuple)
 			return -EOPNOTSUPP;
-		dev->features |= NETIF_F_NTUPLE;
+		features |= NETIF_F_NTUPLE;
 	} else {
 		/* safe to clear regardless */
-		dev->features &= ~NETIF_F_NTUPLE;
+		features &= ~NETIF_F_NTUPLE;
 	}
 
+	dev->features = features;
 	return 0;
 }
 
maintainer Applied
#1 lore raw

From: Jeff Garzik <[email protected]>
Date: Sat, 27 Feb 2010 02:43:38 -0500

Quoted 10 lines

NETIF_F_NTUPLE flag setting introduced a bug: non-ntuple flags like LRO may be successfully set, before ioctl(2) returns failure to userspace.

The set-flags operation should be all-or-none, rather than leaving things in an inconsistent state prior to reporting failure to userspace.

Applied, thanks Jeff.