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

net: add missing instance lock to dev_set_promiscuity

Accidentally spotted while trying to understand what else needs
to be renamed to netif_ prefix. Most of the calls to dev_set_promiscuity
are adjacent to dev_set_allmulti or dev_disable_lro so it should
be safe to add the lock. Note that new netif_set_promiscuity is
currently unused, the locked paths call __dev_set_promiscuity directly.

Fixes: ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations")
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250506011919.2882313-1-sdf@fomichev.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Stanislav Fomichev and committed by
Jakub Kicinski
78cd4083 08e9f2d5

+25 -13
+1
include/linux/netdevice.h
··· 4972 4972 4973 4973 /* Functions used for secondary unicast and multicast support */ 4974 4974 void dev_set_rx_mode(struct net_device *dev); 4975 + int netif_set_promiscuity(struct net_device *dev, int inc); 4975 4976 int dev_set_promiscuity(struct net_device *dev, int inc); 4976 4977 int netif_set_allmulti(struct net_device *dev, int inc, bool notify); 4977 4978 int dev_set_allmulti(struct net_device *dev, int inc);
+1 -13
net/core/dev.c
··· 9193 9193 return 0; 9194 9194 } 9195 9195 9196 - /** 9197 - * dev_set_promiscuity - update promiscuity count on a device 9198 - * @dev: device 9199 - * @inc: modifier 9200 - * 9201 - * Add or remove promiscuity from a device. While the count in the device 9202 - * remains above zero the interface remains promiscuous. Once it hits zero 9203 - * the device reverts back to normal filtering operation. A negative inc 9204 - * value is used to drop promiscuity on the device. 9205 - * Return 0 if successful or a negative errno code on error. 9206 - */ 9207 - int dev_set_promiscuity(struct net_device *dev, int inc) 9196 + int netif_set_promiscuity(struct net_device *dev, int inc) 9208 9197 { 9209 9198 unsigned int old_flags = dev->flags; 9210 9199 int err; ··· 9205 9216 dev_set_rx_mode(dev); 9206 9217 return err; 9207 9218 } 9208 - EXPORT_SYMBOL(dev_set_promiscuity); 9209 9219 9210 9220 int netif_set_allmulti(struct net_device *dev, int inc, bool notify) 9211 9221 {
+23
net/core/dev_api.c
··· 268 268 EXPORT_SYMBOL(dev_disable_lro); 269 269 270 270 /** 271 + * dev_set_promiscuity() - update promiscuity count on a device 272 + * @dev: device 273 + * @inc: modifier 274 + * 275 + * Add or remove promiscuity from a device. While the count in the device 276 + * remains above zero the interface remains promiscuous. Once it hits zero 277 + * the device reverts back to normal filtering operation. A negative inc 278 + * value is used to drop promiscuity on the device. 279 + * Return 0 if successful or a negative errno code on error. 280 + */ 281 + int dev_set_promiscuity(struct net_device *dev, int inc) 282 + { 283 + int ret; 284 + 285 + netdev_lock_ops(dev); 286 + ret = netif_set_promiscuity(dev, inc); 287 + netdev_unlock_ops(dev); 288 + 289 + return ret; 290 + } 291 + EXPORT_SYMBOL(dev_set_promiscuity); 292 + 293 + /** 271 294 * dev_set_allmulti() - update allmulti count on a device 272 295 * @dev: device 273 296 * @inc: modifier