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

Configure Feed

Select the types of activity you want to include in your feed.

mpls: Use mpls_route_input() where appropriate.

In many places, we uses rtnl_dereference() twice for
net->mpls.platform_label and net->mpls.platform_label[index].

Let's replace the code with mpls_route_input().

We do not use mpls_route_input() in mpls_dump_routes() since
we will rely on RCU there.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Guillaume Nault <gnault@redhat.com>
Link: https://patch.msgid.link/20251029173344.2934622-10-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Kuniyuki Iwashima and committed by
Jakub Kicinski
3a496293 73e40539

+13 -19
+13 -19
net/mpls/af_mpls.c
··· 590 590 mpls_rt_free(rt); 591 591 } 592 592 593 - static unsigned find_free_label(struct net *net) 593 + static unsigned int find_free_label(struct net *net) 594 594 { 595 - struct mpls_route __rcu **platform_label; 596 - size_t platform_labels; 597 - unsigned index; 595 + unsigned int index; 598 596 599 - platform_label = rtnl_dereference(net->mpls.platform_label); 600 - platform_labels = net->mpls.platform_labels; 601 - for (index = MPLS_LABEL_FIRST_UNRESERVED; index < platform_labels; 597 + for (index = MPLS_LABEL_FIRST_UNRESERVED; 598 + index < net->mpls.platform_labels; 602 599 index++) { 603 - if (!rtnl_dereference(platform_label[index])) 600 + if (!mpls_route_input(net, index)) 604 601 return index; 605 602 } 603 + 606 604 return LABEL_NOT_SPECIFIED; 607 605 } 608 606 ··· 983 985 static int mpls_route_add(struct mpls_route_config *cfg, 984 986 struct netlink_ext_ack *extack) 985 987 { 986 - struct mpls_route __rcu **platform_label; 987 988 struct net *net = cfg->rc_nlinfo.nl_net; 988 989 struct mpls_route *rt, *old; 989 990 int err = -EINVAL; ··· 1010 1013 } 1011 1014 1012 1015 err = -EEXIST; 1013 - platform_label = rtnl_dereference(net->mpls.platform_label); 1014 - old = rtnl_dereference(platform_label[index]); 1016 + old = mpls_route_input(net, index); 1015 1017 if ((cfg->rc_nlflags & NLM_F_EXCL) && old) 1016 1018 goto errout; 1017 1019 ··· 1499 1503 1500 1504 static int mpls_ifdown(struct net_device *dev, int event) 1501 1505 { 1502 - struct mpls_route __rcu **platform_label; 1503 1506 struct net *net = dev_net(dev); 1504 - unsigned index; 1507 + unsigned int index; 1505 1508 1506 - platform_label = rtnl_dereference(net->mpls.platform_label); 1507 1509 for (index = 0; index < net->mpls.platform_labels; index++) { 1508 - struct mpls_route *rt = rtnl_dereference(platform_label[index]); 1510 + struct mpls_route *rt; 1509 1511 bool nh_del = false; 1510 1512 u8 alive = 0; 1511 1513 1514 + rt = mpls_route_input(net, index); 1512 1515 if (!rt) 1513 1516 continue; 1514 1517 ··· 1578 1583 1579 1584 static void mpls_ifup(struct net_device *dev, unsigned int flags) 1580 1585 { 1581 - struct mpls_route __rcu **platform_label; 1582 1586 struct net *net = dev_net(dev); 1583 - unsigned index; 1587 + unsigned int index; 1584 1588 u8 alive; 1585 1589 1586 - platform_label = rtnl_dereference(net->mpls.platform_label); 1587 1590 for (index = 0; index < net->mpls.platform_labels; index++) { 1588 - struct mpls_route *rt = rtnl_dereference(platform_label[index]); 1591 + struct mpls_route *rt; 1589 1592 1593 + rt = mpls_route_input(net, index); 1590 1594 if (!rt) 1591 1595 continue; 1592 1596