Commit 75cda62d authored by Florian Westphal's avatar Florian Westphal Committed by Steffen Klassert

xfrm: state: simplify rcu_read_unlock handling in two spots

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: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
parent 711059b9
...@@ -231,17 +231,18 @@ static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family) ...@@ -231,17 +231,18 @@ static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
return NULL; return NULL;
typemap = afinfo->type_map; typemap = afinfo->type_map;
type = typemap[proto]; type = READ_ONCE(typemap[proto]);
if (unlikely(type && !try_module_get(type->owner))) if (unlikely(type && !try_module_get(type->owner)))
type = NULL; type = NULL;
if (!type && !modload_attempted) {
rcu_read_unlock(); rcu_read_unlock();
if (!type && !modload_attempted) {
request_module("xfrm-type-%d-%d", family, proto); request_module("xfrm-type-%d-%d", family, proto);
modload_attempted = 1; modload_attempted = 1;
goto retry; goto retry;
} }
rcu_read_unlock();
return type; return type;
} }
...@@ -327,17 +328,17 @@ static struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family) ...@@ -327,17 +328,17 @@ static struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family)
if (unlikely(afinfo == NULL)) if (unlikely(afinfo == NULL))
return NULL; return NULL;
mode = afinfo->mode_map[encap]; mode = READ_ONCE(afinfo->mode_map[encap]);
if (unlikely(mode && !try_module_get(mode->owner))) if (unlikely(mode && !try_module_get(mode->owner)))
mode = NULL; mode = NULL;
if (!mode && !modload_attempted) {
rcu_read_unlock(); rcu_read_unlock();
if (!mode && !modload_attempted) {
request_module("xfrm-mode-%d-%d", family, encap); request_module("xfrm-mode-%d-%d", family, encap);
modload_attempted = 1; modload_attempted = 1;
goto retry; goto retry;
} }
rcu_read_unlock();
return mode; return mode;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment