[PATCH net-next] net/ipv6: silence 'passing zero to ERR_PTR()' warning

From: Haoyi Liu
Date: Thu Apr 06 2023 - 23:54:59 EST


Smatch complains that if xfrm_lookup() returns NULL then this does a
weird thing with "err":

net/ ipv6/ icmp.c:411 icmpv6_route_lookup()
warn: passing zero to ERR_PTR()

Just return "dst2" directly instead of assigning it to"dst" and then
looking up the value of "err". No functional change.

Signed-off-by: Haoyi Liu <iccccc@xxxxxxxxxxx>
Reviewed-by: Dongliang Mu <dzm91@xxxxxxxxxxx>
---
The issue is found by static analysis, and the patch is remains untested.
---
net/ipv6/icmp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 1f53f2a74480..a5e77acead89 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -395,7 +395,7 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net,
dst2 = xfrm_lookup(net, dst2, flowi6_to_flowi(&fl2), sk, XFRM_LOOKUP_ICMP);
if (!IS_ERR(dst2)) {
dst_release(dst);
- dst = dst2;
+ return dst2;
} else {
err = PTR_ERR(dst2);
if (err == -EPERM) {
--
2.25.1