Merge tag 'net-next-5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev...
[linux-2.6-microblaze.git] / net / xfrm / xfrm_policy.c
index ce500f8..827d842 100644 (file)
@@ -1902,8 +1902,7 @@ static int xfrm_policy_match(const struct xfrm_policy *pol,
 
        match = xfrm_selector_match(sel, fl, family);
        if (match)
-               ret = security_xfrm_policy_lookup(pol->security, fl->flowi_secid,
-                                                 dir);
+               ret = security_xfrm_policy_lookup(pol->security, fl->flowi_secid);
        return ret;
 }
 
@@ -2092,12 +2091,15 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
        if (unlikely(!daddr || !saddr))
                return NULL;
 
-       rcu_read_lock();
  retry:
-       do {
-               sequence = read_seqcount_begin(&xfrm_policy_hash_generation);
-               chain = policy_hash_direct(net, daddr, saddr, family, dir);
-       } while (read_seqcount_retry(&xfrm_policy_hash_generation, sequence));
+       sequence = read_seqcount_begin(&xfrm_policy_hash_generation);
+       rcu_read_lock();
+
+       chain = policy_hash_direct(net, daddr, saddr, family, dir);
+       if (read_seqcount_retry(&xfrm_policy_hash_generation, sequence)) {
+               rcu_read_unlock();
+               goto retry;
+       }
 
        ret = NULL;
        hlist_for_each_entry_rcu(pol, chain, bydst) {
@@ -2128,11 +2130,15 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
        }
 
 skip_inexact:
-       if (read_seqcount_retry(&xfrm_policy_hash_generation, sequence))
+       if (read_seqcount_retry(&xfrm_policy_hash_generation, sequence)) {
+               rcu_read_unlock();
                goto retry;
+       }
 
-       if (ret && !xfrm_pol_hold_rcu(ret))
+       if (ret && !xfrm_pol_hold_rcu(ret)) {
+               rcu_read_unlock();
                goto retry;
+       }
 fail:
        rcu_read_unlock();
 
@@ -2181,8 +2187,7 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(const struct sock *sk, int dir,
                                goto out;
                        }
                        err = security_xfrm_policy_lookup(pol->security,
-                                                     fl->flowi_secid,
-                                                     dir);
+                                                     fl->flowi_secid);
                        if (!err) {
                                if (!xfrm_pol_hold_rcu(pol))
                                        goto again;
@@ -3247,7 +3252,7 @@ xfrm_state_ok(const struct xfrm_tmpl *tmpl, const struct xfrm_state *x,
 
 /*
  * 0 or more than 0 is returned when validation is succeeded (either bypass
- * because of optional transport mode, or next index of the mathced secpath
+ * because of optional transport mode, or next index of the matched secpath
  * state with the template.
  * -1 is returned when no matching template is found.
  * Otherwise "-2 - errored_index" is returned.