Skip to content

Commit

Permalink
xfrm: state: simplify rcu_read_unlock handling in two spots
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Florian Westphal authored and Steffen Klassert committed Jan 10, 2017
1 parent 711059b commit 75cda62
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions net/xfrm/xfrm_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,18 @@ static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
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;
}

Expand Down Expand Up @@ -327,17 +328,17 @@ static struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family)
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;
}

Expand Down

0 comments on commit 75cda62

Please sign in to comment.