Commit cc6a7aab authored by Arnd Bergmann's avatar Arnd Bergmann Committed by J. Bruce Fields

sunrpc: avoid warning in gss_key_timeout

The gss_key_timeout() function causes a harmless warning in some
configurations, e.g. ARM imx_v6_v7_defconfig with gcc-5.2, if the
compiler cannot figure out the state of the 'expire' variable across
an rcu_read_unlock():

net/sunrpc/auth_gss/auth_gss.c: In function 'gss_key_timeout':
net/sunrpc/auth_gss/auth_gss.c:1422:211: warning: 'expire' may be used uninitialized in this function [-Wmaybe-uninitialized]

To avoid this warning without adding a bogus initialization, this
rewrites the function so the comparison is done inside of the
critical section. As a side-effect, it also becomes slightly
easier to understand because the implementation now more closely
resembles the comment above it.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Fixes: c5e6aecd ("sunrpc: fix RCU handling of gc_ctx field")
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent 0d0f4aab
...@@ -1411,17 +1411,16 @@ gss_key_timeout(struct rpc_cred *rc) ...@@ -1411,17 +1411,16 @@ gss_key_timeout(struct rpc_cred *rc)
{ {
struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base); struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base);
struct gss_cl_ctx *ctx; struct gss_cl_ctx *ctx;
unsigned long now = jiffies; unsigned long timeout = jiffies + (gss_key_expire_timeo * HZ);
unsigned long expire; int ret = 0;
rcu_read_lock(); rcu_read_lock();
ctx = rcu_dereference(gss_cred->gc_ctx); ctx = rcu_dereference(gss_cred->gc_ctx);
if (ctx) if (!ctx || time_after(timeout, ctx->gc_expiry))
expire = ctx->gc_expiry - (gss_key_expire_timeo * HZ); ret = -EACCES;
rcu_read_unlock(); rcu_read_unlock();
if (!ctx || time_after(now, expire))
return -EACCES; return ret;
return 0;
} }
static int static int
......
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