Skip to contentSkip to conversation

ipv6: Use local variable for ifa->flags in inet6_fill_ifaddr

PATCH In review Zilin Guan 2 participants 2 messages Nov 4, 2024

Subsystems (3)
lore
Share & tools
lore

Zilin Guan

author
#0 lore raw

PATCH 1/1 ipv6: Use local variable for ifa->flags in inet6_fill_ifaddr

Currently, the inet6_fill_ifaddr() function reads the value of ifa->flags using READ_ONCE() and stores it in the local variable flags. However, the subsequent call to put_ifaddrmsg() uses ifa->flags again instead of the already read local variable. This re-read is unnecessary because no other thread can modify ifa->flags between the initial READ_ONCE() and the subsequent use in put_ifaddrmsg().

---
 net/ipv6/addrconf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/addrconf.c +1 -1
index 94dceac52884..c4b080471b39 100644
@@ -5143,7 +5143,7 @@ static int inet6_fill_ifaddr(struct sk_buff *skb,
 		return -EMSGSIZE;
 
 	flags = READ_ONCE(ifa->flags);
-	put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope),
+	put_ifaddrmsg(nlh, ifa->prefix_len, flags, rt_scope(ifa->scope),
 		      ifa->idev->dev->ifindex);
 
 	if (args->netnsid >= 0 &&
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Zilin Guan

Currently, the inet6_fill_ifaddr() function reads the value of ifa->flags using READ_ONCE() and stores it in the local variable flags. However, the subsequent call to put_ifaddrmsg() uses ifa->flags again instead of the already read local variable. This re-read is unnecessary because no other thread can modify ifa->flags between the initial READ_ONCE() and the subsequent use in put_ifaddrmsg().

I do not think this last sentence is true. I would rephrase this or remove it.

Otherwise, patch looks fine to me, thanks.

Quoted 22 lines
---
 net/ipv6/addrconf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/addrconf.c +1 -2
index 94dceac52884..c4b080471b39 100644
@@ -5143,7 +5143,7 @@ static int inet6_fill_ifaddr(struct sk_buff *skb,
                return -EMSGSIZE;
 
        flags = READ_ONCE(ifa->flags);
-       put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope),
+       put_ifaddrmsg(nlh, ifa->prefix_len, flags, rt_scope(ifa->scope),
                      ifa->idev->dev->ifindex);
 
        if (args->netnsid >= 0 &&
--

2.34.1