Skip to content

Commit 7863c05

Browse files
Veaceslav Falicodavem330
authored andcommitted
net: use lists as arguments instead of bool upper
Currently we make use of bool upper when we want to specify if we want to work with upper/lower list. It's, however, harder to read, debug and occupies a lot more code. Fix this by just passing the correct upper/lower_dev_list list_head pointer instead of bool upper, and work internally with it. CC: "David S. Miller" <[email protected]> CC: Eric Dumazet <[email protected]> CC: Jiri Pirko <[email protected]> CC: Alexander Duyck <[email protected]> CC: Cong Wang <[email protected]> Signed-off-by: Veaceslav Falico <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4ed377e commit 7863c05

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

net/core/dev.c

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,12 +4385,9 @@ struct netdev_adjacent {
43854385

43864386
static struct netdev_adjacent *__netdev_find_adj(struct net_device *dev,
43874387
struct net_device *adj_dev,
4388-
bool upper)
4388+
struct list_head *dev_list)
43894389
{
43904390
struct netdev_adjacent *adj;
4391-
struct list_head *dev_list;
4392-
4393-
dev_list = upper ? &dev->upper_dev_list : &dev->lower_dev_list;
43944391

43954392
list_for_each_entry(adj, dev_list, list) {
43964393
if (adj->dev == adj_dev)
@@ -4402,13 +4399,13 @@ static struct netdev_adjacent *__netdev_find_adj(struct net_device *dev,
44024399
static inline struct netdev_adjacent *__netdev_find_upper(struct net_device *dev,
44034400
struct net_device *udev)
44044401
{
4405-
return __netdev_find_adj(dev, udev, true);
4402+
return __netdev_find_adj(dev, udev, &dev->upper_dev_list);
44064403
}
44074404

44084405
static inline struct netdev_adjacent *__netdev_find_lower(struct net_device *dev,
44094406
struct net_device *ldev)
44104407
{
4411-
return __netdev_find_adj(dev, ldev, false);
4408+
return __netdev_find_adj(dev, ldev, &dev->lower_dev_list);
44124409
}
44134410

44144411
/**
@@ -4514,12 +4511,12 @@ EXPORT_SYMBOL(netdev_master_upper_dev_get_rcu);
45144511

45154512
static int __netdev_adjacent_dev_insert(struct net_device *dev,
45164513
struct net_device *adj_dev,
4517-
bool neighbour, bool master,
4518-
bool upper)
4514+
struct list_head *dev_list,
4515+
bool neighbour, bool master)
45194516
{
45204517
struct netdev_adjacent *adj;
45214518

4522-
adj = __netdev_find_adj(dev, adj_dev, upper);
4519+
adj = __netdev_find_adj(dev, adj_dev, dev_list);
45234520

45244521
if (adj) {
45254522
BUG_ON(neighbour);
@@ -4538,19 +4535,14 @@ static int __netdev_adjacent_dev_insert(struct net_device *dev,
45384535

45394536
dev_hold(adj_dev);
45404537
pr_debug("dev_hold for %s, because of %s link added from %s to %s\n",
4541-
adj_dev->name, upper ? "upper" : "lower", dev->name,
4542-
adj_dev->name);
4538+
adj_dev->name, dev_list == &dev->upper_dev_list ?
4539+
"upper" : "lower", dev->name, adj_dev->name);
45434540

4544-
if (!upper) {
4545-
list_add_tail_rcu(&adj->list, &dev->lower_dev_list);
4546-
return 0;
4547-
}
4548-
4549-
/* Ensure that master upper link is always the first item in list. */
4541+
/* Ensure that master link is always the first item in list. */
45504542
if (master)
4551-
list_add_rcu(&adj->list, &dev->upper_dev_list);
4543+
list_add_rcu(&adj->list, dev_list);
45524544
else
4553-
list_add_tail_rcu(&adj->list, &dev->upper_dev_list);
4545+
list_add_tail_rcu(&adj->list, dev_list);
45544546

45554547
return 0;
45564548
}
@@ -4559,27 +4551,25 @@ static inline int __netdev_upper_dev_insert(struct net_device *dev,
45594551
struct net_device *udev,
45604552
bool master, bool neighbour)
45614553
{
4562-
return __netdev_adjacent_dev_insert(dev, udev, neighbour, master,
4563-
true);
4554+
return __netdev_adjacent_dev_insert(dev, udev, &dev->upper_dev_list,
4555+
neighbour, master);
45644556
}
45654557

45664558
static inline int __netdev_lower_dev_insert(struct net_device *dev,
45674559
struct net_device *ldev,
45684560
bool neighbour)
45694561
{
4570-
return __netdev_adjacent_dev_insert(dev, ldev, neighbour, false,
4571-
false);
4562+
return __netdev_adjacent_dev_insert(dev, ldev, &dev->lower_dev_list,
4563+
neighbour, false);
45724564
}
45734565

45744566
void __netdev_adjacent_dev_remove(struct net_device *dev,
4575-
struct net_device *adj_dev, bool upper)
4567+
struct net_device *adj_dev,
4568+
struct list_head *dev_list)
45764569
{
45774570
struct netdev_adjacent *adj;
45784571

4579-
if (upper)
4580-
adj = __netdev_find_upper(dev, adj_dev);
4581-
else
4582-
adj = __netdev_find_lower(dev, adj_dev);
4572+
adj = __netdev_find_adj(dev, adj_dev, dev_list);
45834573

45844574
if (!adj)
45854575
BUG();
@@ -4591,22 +4581,22 @@ void __netdev_adjacent_dev_remove(struct net_device *dev,
45914581

45924582
list_del_rcu(&adj->list);
45934583
pr_debug("dev_put for %s, because of %s link removed from %s to %s\n",
4594-
adj_dev->name, upper ? "upper" : "lower", dev->name,
4595-
adj_dev->name);
4584+
adj_dev->name, dev_list == &dev->upper_dev_list ?
4585+
"upper" : "lower", dev->name, adj_dev->name);
45964586
dev_put(adj_dev);
45974587
kfree_rcu(adj, rcu);
45984588
}
45994589

46004590
static inline void __netdev_upper_dev_remove(struct net_device *dev,
46014591
struct net_device *udev)
46024592
{
4603-
return __netdev_adjacent_dev_remove(dev, udev, true);
4593+
return __netdev_adjacent_dev_remove(dev, udev, &dev->upper_dev_list);
46044594
}
46054595

46064596
static inline void __netdev_lower_dev_remove(struct net_device *dev,
46074597
struct net_device *ldev)
46084598
{
4609-
return __netdev_adjacent_dev_remove(dev, ldev, false);
4599+
return __netdev_adjacent_dev_remove(dev, ldev, &dev->lower_dev_list);
46104600
}
46114601

46124602
int __netdev_adjacent_dev_insert_link(struct net_device *dev,

0 commit comments

Comments
 (0)