xfrm: state: simplify rcu_read_unlock handling in two spots
authorFlorian Westphal <fw@strlen.de>
Mon, 9 Jan 2017 13:20:49 +0000 (14:20 +0100)
committerSteffen Klassert <steffen.klassert@secunet.com>
Tue, 10 Jan 2017 09:57:14 +0000 (10:57 +0100)
Instead of:
  if (foo) {
      unlock();
      return bar();
   }
   unlock();
do:
   unlock();
   if (foo)
       return bar();

This is ok because rcu protected structure is only dereferenced before
the conditional.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_state.c

index b5dad899fb0e42f8951b64fd8a2c32c978dd2ee8..a62097e640b5690edc4d6f9bf794d1a2c80725f7 100644 (file)
@@ -231,17 +231,18 @@ retry:
                return NULL;
        typemap = afinfo->type_map;
 
-       type = typemap[proto];
+       type = READ_ONCE(typemap[proto]);
        if (unlikely(type && !try_module_get(type->owner)))
                type = NULL;
+
+       rcu_read_unlock();
+
        if (!type && !modload_attempted) {
-               rcu_read_unlock();
                request_module("xfrm-type-%d-%d", family, proto);
                modload_attempted = 1;
                goto retry;
        }
 
-       rcu_read_unlock();
        return type;
 }
 
@@ -327,17 +328,17 @@ retry:
        if (unlikely(afinfo == NULL))
                return NULL;
 
-       mode = afinfo->mode_map[encap];
+       mode = READ_ONCE(afinfo->mode_map[encap]);
        if (unlikely(mode && !try_module_get(mode->owner)))
                mode = NULL;
+
+       rcu_read_unlock();
        if (!mode && !modload_attempted) {
-               rcu_read_unlock();
                request_module("xfrm-mode-%d-%d", family, encap);
                modload_attempted = 1;
                goto retry;
        }
 
-       rcu_read_unlock();
        return mode;
 }