Skip to contentSkip to conversation

net: mpls: Cleanup nexthop iterator macros

PATCH Applied Benjamin Poirier 2 participants 4 messages Nov 29, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover net: mpls: Cleanup nexthop iterator macros

From: Benjamin Poirier <[email protected]>

The mpls macros for_nexthops and change_nexthops were probably copied from decnet or ipv4 but they grew a superfluous variable and lost a beneficial "const".

Benjamin Poirier (2):
net: mpls: Remove duplicate variable from iterator macro
net: mpls: Make for_nexthops iterator const

 net/mpls/af_mpls.c  |  8 ++++----
 net/mpls/internal.h | 13 ++++++-------
 2 files changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.33.1
#1 lore raw

PATCH 1/2 net: mpls: Remove duplicate variable from iterator macro

__nh is just a copy of nh with a different type.

---
 net/mpls/internal.h | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
net/mpls/internal.h +6 -7
index 838cdfc10e47..218138f5b491 100644
@@ -158,17 +158,16 @@ struct mpls_route { /* next hop label forwarding entry */
 };
 
 #define for_nexthops(rt) {						\
-	int nhsel; struct mpls_nh *nh;  u8 *__nh;			\
-	for (nhsel = 0, nh = (rt)->rt_nh, __nh = (u8 *)((rt)->rt_nh);	\
+	int nhsel; struct mpls_nh *nh;					\
+	for (nhsel = 0, nh = (rt)->rt_nh;				\
 	     nhsel < (rt)->rt_nhn;					\
-	     __nh += rt->rt_nh_size, nh = (struct mpls_nh *)__nh, nhsel++)
+	     nh = (void *)nh + (rt)->rt_nh_size, nhsel++)
 
 #define change_nexthops(rt) {						\
-	int nhsel; struct mpls_nh *nh; u8 *__nh;			\
-	for (nhsel = 0, nh = (struct mpls_nh *)((rt)->rt_nh),		\
-			__nh = (u8 *)((rt)->rt_nh);			\
+	int nhsel; struct mpls_nh *nh;					\
+	for (nhsel = 0, nh = (rt)->rt_nh;				\
 	     nhsel < (rt)->rt_nhn;					\
-	     __nh += rt->rt_nh_size, nh = (struct mpls_nh *)__nh, nhsel++)
+	     nh = (void *)nh + (rt)->rt_nh_size, nhsel++)
 
 #define endfor_nexthops(rt) }
 
Signature · 1 line
2.33.1
#2 lore raw

PATCH 2/2 net: mpls: Make for_nexthops iterator const

In reply to Benjamin Poirier

There are separate for_nexthops and change_nexthops iterators. The for_nexthops variant should use const.

---
 net/mpls/af_mpls.c  | 8 ++++----
 net/mpls/internal.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
net/mpls/af_mpls.c +4 -4
index ffeb2df8be7a..9fab40aa5c84 100644
@@ -230,8 +230,8 @@ static struct mpls_nh *mpls_get_nexthop(struct mpls_route *rt, u8 index)
  * Since those fields can change at any moment, use READ_ONCE to
  * access both.
  */
-static struct mpls_nh *mpls_select_multipath(struct mpls_route *rt,
-					     struct sk_buff *skb)
+static const struct mpls_nh *mpls_select_multipath(struct mpls_route *rt,
+						   struct sk_buff *skb)
 {
 	u32 hash = 0;
 	int nh_index = 0;
@@ -343,8 +343,8 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
 {
 	struct net *net = dev_net(dev);
 	struct mpls_shim_hdr *hdr;
+	const struct mpls_nh *nh;
 	struct mpls_route *rt;
-	struct mpls_nh *nh;
 	struct mpls_entry_decoded dec;
 	struct net_device *out_dev;
 	struct mpls_dev *out_mdev;
@@ -2333,12 +2333,12 @@ static int mpls_getroute(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
 	u32 labels[MAX_NEW_LABELS];
 	struct mpls_shim_hdr *hdr;
 	unsigned int hdr_size = 0;
+	const struct mpls_nh *nh;
 	struct net_device *dev;
 	struct mpls_route *rt;
 	struct rtmsg *rtm, *r;
 	struct nlmsghdr *nlh;
 	struct sk_buff *skb;
-	struct mpls_nh *nh;
 	u8 n_labels;
 	int err;
 
net/mpls/internal.h +1 -1
index 218138f5b491..56c5cad3a230 100644
@@ -158,7 +158,7 @@ struct mpls_route { /* next hop label forwarding entry */
 };
 
 #define for_nexthops(rt) {						\
-	int nhsel; struct mpls_nh *nh;					\
+	int nhsel; const struct mpls_nh *nh;				\
 	for (nhsel = 0, nh = (rt)->rt_nh;				\
 	     nhsel < (rt)->rt_nhn;					\
 	     nh = (void *)nh + (rt)->rt_nh_size, nhsel++)
Signature · 1 line
2.33.1
#3 lore raw
In reply to Benjamin Poirier
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 11 lines · On Mon, 29 Nov 2021 15:23:14 +0900 you wrote:

From: Benjamin Poirier <[email protected]>

The mpls macros for_nexthops and change_nexthops were probably copied from decnet or ipv4 but they grew a superfluous variable and lost a beneficial "const".

Benjamin Poirier (2):
net: mpls: Remove duplicate variable from iterator macro
net: mpls: Make for_nexthops iterator const

[...]

Here is the summary with links:
- [net-next,1/2] net: mpls: Remove duplicate variable from iterator macro

    https://git.kernel.org/netdev/net-next/c/69d9c0d07726
  - [net-next,2/2] net: mpls: Make for_nexthops iterator const
    https://git.kernel.org/netdev/net-next/c/f05b0b97335b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html