net: hold netdev instance lock during sysfs operations

Most of them are already covered by the converted dev_xxx APIs.
Add the locking wrappers for the remaining ones.

Cc: Saeed Mahameed <saeed@kernel.org>
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250305163732.2766420-9-sdf@fomichev.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Stanislav Fomichev
2025-03-05 08:37:26 -08:00
committed by Jakub Kicinski
parent ffb7ed19ac
commit ad7c7b2172
5 changed files with 88 additions and 48 deletions

View File

@@ -252,3 +252,68 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
return ret;
}
EXPORT_SYMBOL(dev_set_mtu);
/**
* dev_disable_lro() - disable Large Receive Offload on a device
* @dev: device
*
* Disable Large Receive Offload (LRO) on a net device. Must be
* called under RTNL. This is needed if received packets may be
* forwarded to another interface.
*/
void dev_disable_lro(struct net_device *dev)
{
netdev_lock_ops(dev);
netif_disable_lro(dev);
netdev_unlock_ops(dev);
}
EXPORT_SYMBOL(dev_disable_lro);
/**
* dev_set_allmulti() - update allmulti count on a device
* @dev: device
* @inc: modifier
*
* Add or remove reception of all multicast frames to a device. While the
* count in the device remains above zero the interface remains listening
* to all interfaces. Once it hits zero the device reverts back to normal
* filtering operation. A negative @inc value is used to drop the counter
* when releasing a resource needing all multicasts.
*
* Return: 0 on success, -errno on failure.
*/
int dev_set_allmulti(struct net_device *dev, int inc)
{
int ret;
netdev_lock_ops(dev);
ret = netif_set_allmulti(dev, inc, true);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL(dev_set_allmulti);
/**
* dev_set_mac_address() - change Media Access Control Address
* @dev: device
* @sa: new address
* @extack: netlink extended ack
*
* Change the hardware (MAC) address of the device
*
* Return: 0 on success, -errno on failure.
*/
int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
struct netlink_ext_ack *extack)
{
int ret;
netdev_lock_ops(dev);
ret = netif_set_mac_address(dev, sa, extack);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL(dev_set_mac_address);