Skip to content
Snippets Groups Projects
Commit 7581fdf6 authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman
Browse files

cred: allow get_cred() and put_cred() to be given NULL.


commit f06bc033 upstream.

It is common practice for helpers like this to silently,
accept a NULL pointer.
get_rpccred() and put_rpccred() used by NFS act this way
and using the same interface will ease the conversion
for NFS, and simplify the resulting code.

Signed-off-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 764ac04d
No related branches found
No related tags found
No related merge requests found
...@@ -240,7 +240,7 @@ static inline struct cred *get_new_cred(struct cred *cred) ...@@ -240,7 +240,7 @@ static inline struct cred *get_new_cred(struct cred *cred)
* @cred: The credentials to reference * @cred: The credentials to reference
* *
* Get a reference on the specified set of credentials. The caller must * Get a reference on the specified set of credentials. The caller must
* release the reference. * release the reference. If %NULL is passed, it is returned with no action.
* *
* This is used to deal with a committed set of credentials. Although the * This is used to deal with a committed set of credentials. Although the
* pointer is const, this will temporarily discard the const and increment the * pointer is const, this will temporarily discard the const and increment the
...@@ -251,6 +251,8 @@ static inline struct cred *get_new_cred(struct cred *cred) ...@@ -251,6 +251,8 @@ static inline struct cred *get_new_cred(struct cred *cred)
static inline const struct cred *get_cred(const struct cred *cred) static inline const struct cred *get_cred(const struct cred *cred)
{ {
struct cred *nonconst_cred = (struct cred *) cred; struct cred *nonconst_cred = (struct cred *) cred;
if (!cred)
return cred;
validate_creds(cred); validate_creds(cred);
nonconst_cred->non_rcu = 0; nonconst_cred->non_rcu = 0;
return get_new_cred(nonconst_cred); return get_new_cred(nonconst_cred);
...@@ -261,7 +263,7 @@ static inline const struct cred *get_cred(const struct cred *cred) ...@@ -261,7 +263,7 @@ static inline const struct cred *get_cred(const struct cred *cred)
* @cred: The credentials to release * @cred: The credentials to release
* *
* Release a reference to a set of credentials, deleting them when the last ref * Release a reference to a set of credentials, deleting them when the last ref
* is released. * is released. If %NULL is passed, nothing is done.
* *
* This takes a const pointer to a set of credentials because the credentials * This takes a const pointer to a set of credentials because the credentials
* on task_struct are attached by const pointers to prevent accidental * on task_struct are attached by const pointers to prevent accidental
...@@ -271,9 +273,11 @@ static inline void put_cred(const struct cred *_cred) ...@@ -271,9 +273,11 @@ static inline void put_cred(const struct cred *_cred)
{ {
struct cred *cred = (struct cred *) _cred; struct cred *cred = (struct cred *) _cred;
validate_creds(cred); if (cred) {
if (atomic_dec_and_test(&(cred)->usage)) validate_creds(cred);
__put_cred(cred); if (atomic_dec_and_test(&(cred)->usage))
__put_cred(cred);
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment