Skip to content

Commit d3fff6c

Browse files
Eric Dumazetdavem330
Eric Dumazet
authored andcommitted
net: add netdev_lockdep_set_classes() helper
It is time to add netdev_lockdep_set_classes() helper so that lockdep annotations per device type are easier to manage. This removes a lot of copies and missing annotations. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 52fbb29 commit d3fff6c

File tree

7 files changed

+23
-82
lines changed

7 files changed

+23
-82
lines changed

drivers/net/bonding/bond_main.c

+1-23
Original file line numberDiff line numberDiff line change
@@ -4607,28 +4607,6 @@ static int bond_check_params(struct bond_params *params)
46074607
return 0;
46084608
}
46094609

4610-
static struct lock_class_key bonding_netdev_xmit_lock_key;
4611-
static struct lock_class_key bonding_netdev_addr_lock_key;
4612-
static struct lock_class_key bonding_tx_busylock_key;
4613-
static struct lock_class_key bonding_qdisc_running_key;
4614-
4615-
static void bond_set_lockdep_class_one(struct net_device *dev,
4616-
struct netdev_queue *txq,
4617-
void *_unused)
4618-
{
4619-
lockdep_set_class(&txq->_xmit_lock,
4620-
&bonding_netdev_xmit_lock_key);
4621-
}
4622-
4623-
static void bond_set_lockdep_class(struct net_device *dev)
4624-
{
4625-
lockdep_set_class(&dev->addr_list_lock,
4626-
&bonding_netdev_addr_lock_key);
4627-
netdev_for_each_tx_queue(dev, bond_set_lockdep_class_one, NULL);
4628-
dev->qdisc_tx_busylock = &bonding_tx_busylock_key;
4629-
dev->qdisc_running_key = &bonding_qdisc_running_key;
4630-
}
4631-
46324610
/* Called from registration process */
46334611
static int bond_init(struct net_device *bond_dev)
46344612
{
@@ -4641,7 +4619,7 @@ static int bond_init(struct net_device *bond_dev)
46414619
if (!bond->wq)
46424620
return -ENOMEM;
46434621

4644-
bond_set_lockdep_class(bond_dev);
4622+
netdev_lockdep_set_classes(bond_dev);
46454623

46464624
list_add_tail(&bond->bond_list, &bn->dev_list);
46474625

drivers/net/ppp/ppp_generic.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -1312,13 +1312,9 @@ ppp_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats64)
13121312
return stats64;
13131313
}
13141314

1315-
static struct lock_class_key ppp_tx_busylock;
1316-
static struct lock_class_key ppp_qdisc_running_key;
1317-
13181315
static int ppp_dev_init(struct net_device *dev)
13191316
{
1320-
dev->qdisc_tx_busylock = &ppp_tx_busylock;
1321-
dev->qdisc_running_key = &ppp_qdisc_running_key;
1317+
netdev_lockdep_set_classes(dev);
13221318
return 0;
13231319
}
13241320

drivers/net/team/team.c

+1-20
Original file line numberDiff line numberDiff line change
@@ -1574,25 +1574,6 @@ static const struct team_option team_options[] = {
15741574
},
15751575
};
15761576

1577-
static struct lock_class_key team_netdev_xmit_lock_key;
1578-
static struct lock_class_key team_netdev_addr_lock_key;
1579-
static struct lock_class_key team_tx_busylock_key;
1580-
static struct lock_class_key team_qdisc_running_key;
1581-
1582-
static void team_set_lockdep_class_one(struct net_device *dev,
1583-
struct netdev_queue *txq,
1584-
void *unused)
1585-
{
1586-
lockdep_set_class(&txq->_xmit_lock, &team_netdev_xmit_lock_key);
1587-
}
1588-
1589-
static void team_set_lockdep_class(struct net_device *dev)
1590-
{
1591-
lockdep_set_class(&dev->addr_list_lock, &team_netdev_addr_lock_key);
1592-
netdev_for_each_tx_queue(dev, team_set_lockdep_class_one, NULL);
1593-
dev->qdisc_tx_busylock = &team_tx_busylock_key;
1594-
dev->qdisc_running_key = &team_qdisc_running_key;
1595-
}
15961577

15971578
static int team_init(struct net_device *dev)
15981579
{
@@ -1628,7 +1609,7 @@ static int team_init(struct net_device *dev)
16281609
goto err_options_register;
16291610
netif_carrier_off(dev);
16301611

1631-
team_set_lockdep_class(dev);
1612+
netdev_lockdep_set_classes(dev);
16321613

16331614
return 0;
16341615

include/linux/netdevice.h

+17
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,23 @@ static inline void netdev_for_each_tx_queue(struct net_device *dev,
19461946
f(dev, &dev->_tx[i], arg);
19471947
}
19481948

1949+
#define netdev_lockdep_set_classes(dev) \
1950+
{ \
1951+
static struct lock_class_key qdisc_tx_busylock_key; \
1952+
static struct lock_class_key qdisc_running_key; \
1953+
static struct lock_class_key qdisc_xmit_lock_key; \
1954+
static struct lock_class_key dev_addr_list_lock_key; \
1955+
unsigned int i; \
1956+
\
1957+
(dev)->qdisc_tx_busylock = &qdisc_tx_busylock_key; \
1958+
(dev)->qdisc_running_key = &qdisc_running_key; \
1959+
lockdep_set_class(&(dev)->addr_list_lock, \
1960+
&dev_addr_list_lock_key); \
1961+
for (i = 0; i < (dev)->num_tx_queues; i++) \
1962+
lockdep_set_class(&(dev)->_tx[i]._xmit_lock, \
1963+
&qdisc_xmit_lock_key); \
1964+
}
1965+
19491966
struct netdev_queue *netdev_pick_tx(struct net_device *dev,
19501967
struct sk_buff *skb,
19511968
void *accel_priv);

net/bluetooth/6lowpan.c

+1-14
Original file line numberDiff line numberDiff line change
@@ -627,22 +627,9 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)
627627
return err < 0 ? NET_XMIT_DROP : err;
628628
}
629629

630-
static struct lock_class_key bt_tx_busylock;
631-
static struct lock_class_key bt_netdev_xmit_lock_key;
632-
static struct lock_class_key bt_qdisc_running_key;
633-
634-
static void bt_set_lockdep_class_one(struct net_device *dev,
635-
struct netdev_queue *txq,
636-
void *_unused)
637-
{
638-
lockdep_set_class(&txq->_xmit_lock, &bt_netdev_xmit_lock_key);
639-
}
640-
641630
static int bt_dev_init(struct net_device *dev)
642631
{
643-
netdev_for_each_tx_queue(dev, bt_set_lockdep_class_one, NULL);
644-
dev->qdisc_tx_busylock = &bt_tx_busylock;
645-
dev->qdisc_running_key = &bt_qdisc_running_key;
632+
netdev_lockdep_set_classes(dev);
646633

647634
return 0;
648635
}

net/ieee802154/6lowpan/core.c

+1-15
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,9 @@ static struct header_ops lowpan_header_ops = {
5858
.create = lowpan_header_create,
5959
};
6060

61-
static struct lock_class_key lowpan_tx_busylock;
62-
static struct lock_class_key lowpan_netdev_xmit_lock_key;
63-
static struct lock_class_key lowpan_qdisc_running_key;
64-
65-
static void lowpan_set_lockdep_class_one(struct net_device *ldev,
66-
struct netdev_queue *txq,
67-
void *_unused)
68-
{
69-
lockdep_set_class(&txq->_xmit_lock,
70-
&lowpan_netdev_xmit_lock_key);
71-
}
72-
7361
static int lowpan_dev_init(struct net_device *ldev)
7462
{
75-
netdev_for_each_tx_queue(ldev, lowpan_set_lockdep_class_one, NULL);
76-
ldev->qdisc_tx_busylock = &lowpan_tx_busylock;
77-
ldev->qdisc_running_key = &lowpan_qdisc_running_key;
63+
netdev_lockdep_set_classes(ldev);
7864

7965
return 0;
8066
}

net/l2tp/l2tp_eth.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@ static inline struct l2tp_eth_net *l2tp_eth_pernet(struct net *net)
6767
return net_generic(net, l2tp_eth_net_id);
6868
}
6969

70-
static struct lock_class_key l2tp_eth_tx_busylock;
71-
static struct lock_class_key l2tp_qdisc_running_key;
72-
7370
static int l2tp_eth_dev_init(struct net_device *dev)
7471
{
7572
struct l2tp_eth *priv = netdev_priv(dev);
7673

7774
priv->dev = dev;
7875
eth_hw_addr_random(dev);
7976
eth_broadcast_addr(dev->broadcast);
80-
dev->qdisc_tx_busylock = &l2tp_eth_tx_busylock;
81-
dev->qdisc_running_key = &l2tp_qdisc_running_key;
77+
netdev_lockdep_set_classes(dev);
8278

8379
return 0;
8480
}

0 commit comments

Comments
 (0)