]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
RDMA/core: Squash a single user static function
authorParav Pandit <parav@nvidia.com>
Tue, 16 Sep 2025 11:11:00 +0000 (14:11 +0300)
committerLeon Romanovsky <leon@kernel.org>
Thu, 18 Sep 2025 09:15:39 +0000 (05:15 -0400)
To reduce dependencies in IFF_LOOPBACK in route and neighbour resolution
steps, squash the static function to its single caller and simplify the
code.
Until now, network field was set even when neighbour resolution failed.
With this change, dev_addr output fields are valid only when resolution
is successful.

Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Vlad Dumitrescu <vdumitrescu@nvidia.com>
Signed-off-by: Edward Srouji <edwards@nvidia.com>
Link: https://patch.msgid.link/20250916111103.84069-2-edwards@nvidia.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/core/addr.c

index be0743dac3fff337b3aa59b417068b5edb0e395b..594e7ee335f7d3515db23a6fa0ac3531f9b4a16e 100644 (file)
@@ -465,34 +465,6 @@ static int addr_resolve_neigh(const struct dst_entry *dst,
        return ret;
 }
 
-static int copy_src_l2_addr(struct rdma_dev_addr *dev_addr,
-                           const struct sockaddr *dst_in,
-                           const struct dst_entry *dst,
-                           const struct net_device *ndev)
-{
-       int ret = 0;
-
-       if (dst->dev->flags & IFF_LOOPBACK)
-               ret = rdma_translate_ip(dst_in, dev_addr);
-       else
-               rdma_copy_src_l2_addr(dev_addr, dst->dev);
-
-       /*
-        * If there's a gateway and type of device not ARPHRD_INFINIBAND,
-        * we're definitely in RoCE v2 (as RoCE v1 isn't routable) set the
-        * network type accordingly.
-        */
-       if (has_gateway(dst, dst_in->sa_family) &&
-           ndev->type != ARPHRD_INFINIBAND)
-               dev_addr->network = dst_in->sa_family == AF_INET ?
-                                               RDMA_NETWORK_IPV4 :
-                                               RDMA_NETWORK_IPV6;
-       else
-               dev_addr->network = RDMA_NETWORK_IB;
-
-       return ret;
-}
-
 static int rdma_set_src_addr_rcu(struct rdma_dev_addr *dev_addr,
                                 unsigned int *ndev_flags,
                                 const struct sockaddr *dst_in,
@@ -503,6 +475,7 @@ static int rdma_set_src_addr_rcu(struct rdma_dev_addr *dev_addr,
        *ndev_flags = ndev->flags;
        /* A physical device must be the RDMA device to use */
        if (ndev->flags & IFF_LOOPBACK) {
+               int ret;
                /*
                 * RDMA (IB/RoCE, iWarp) doesn't run on lo interface or
                 * loopback IP address. So if route is resolved to loopback
@@ -512,9 +485,27 @@ static int rdma_set_src_addr_rcu(struct rdma_dev_addr *dev_addr,
                ndev = rdma_find_ndev_for_src_ip_rcu(dev_net(ndev), dst_in);
                if (IS_ERR(ndev))
                        return -ENODEV;
+               ret = rdma_translate_ip(dst_in, dev_addr);
+               if (ret)
+                       return ret;
+       } else {
+               rdma_copy_src_l2_addr(dev_addr, dst->dev);
        }
 
-       return copy_src_l2_addr(dev_addr, dst_in, dst, ndev);
+       /*
+        * If there's a gateway and type of device not ARPHRD_INFINIBAND,
+        * we're definitely in RoCE v2 (as RoCE v1 isn't routable) set the
+        * network type accordingly.
+        */
+       if (has_gateway(dst, dst_in->sa_family) &&
+           ndev->type != ARPHRD_INFINIBAND)
+               dev_addr->network = dst_in->sa_family == AF_INET ?
+                                               RDMA_NETWORK_IPV4 :
+                                               RDMA_NETWORK_IPV6;
+       else
+               dev_addr->network = RDMA_NETWORK_IB;
+
+       return 0;
 }
 
 static int set_addr_netns_by_gid_rcu(struct rdma_dev_addr *addr)