SUNRPC: Ensure get_rpccred() and put_rpccred() can take NULL arguments

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Trond Myklebust 2016-05-16 17:42:42 -04:00 committed by Anna Schumaker
parent f538d0ba5b
commit 9a8f6b5ea2
2 changed files with 5 additions and 3 deletions

View File

@ -202,7 +202,8 @@ char * rpcauth_stringify_acceptor(struct rpc_cred *);
static inline static inline
struct rpc_cred * get_rpccred(struct rpc_cred *cred) struct rpc_cred * get_rpccred(struct rpc_cred *cred)
{ {
atomic_inc(&cred->cr_count); if (cred != NULL)
atomic_inc(&cred->cr_count);
return cred; return cred;
} }

View File

@ -703,8 +703,7 @@ rpcauth_bindcred(struct rpc_task *task, struct rpc_cred *cred, int flags)
new = rpcauth_bind_new_cred(task, lookupflags); new = rpcauth_bind_new_cred(task, lookupflags);
if (IS_ERR(new)) if (IS_ERR(new))
return PTR_ERR(new); return PTR_ERR(new);
if (req->rq_cred != NULL) put_rpccred(req->rq_cred);
put_rpccred(req->rq_cred);
req->rq_cred = new; req->rq_cred = new;
return 0; return 0;
} }
@ -712,6 +711,8 @@ rpcauth_bindcred(struct rpc_task *task, struct rpc_cred *cred, int flags)
void void
put_rpccred(struct rpc_cred *cred) put_rpccred(struct rpc_cred *cred)
{ {
if (cred == NULL)
return;
/* Fast path for unhashed credentials */ /* Fast path for unhashed credentials */
if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) == 0) { if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) == 0) {
if (atomic_dec_and_test(&cred->cr_count)) if (atomic_dec_and_test(&cred->cr_count))