|
@@ -206,5 +206,23 @@ struct rpc_cred * get_rpccred(struct rpc_cred *cred)
|
|
return cred;
|
|
return cred;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * get_rpccred_rcu - get a reference to a cred using rcu-protected pointer
|
|
|
|
+ * @cred: cred of which to take a reference
|
|
|
|
+ *
|
|
|
|
+ * In some cases, we may have a pointer to a credential to which we
|
|
|
|
+ * want to take a reference, but don't already have one. Because these
|
|
|
|
+ * objects are freed using RCU, we can access the cr_count while its
|
|
|
|
+ * on its way to destruction and only take a reference if it's not already
|
|
|
|
+ * zero.
|
|
|
|
+ */
|
|
|
|
+static inline struct rpc_cred *
|
|
|
|
+get_rpccred_rcu(struct rpc_cred *cred)
|
|
|
|
+{
|
|
|
|
+ if (atomic_inc_not_zero(&cred->cr_count))
|
|
|
|
+ return cred;
|
|
|
|
+ return NULL;
|
|
|
|
+}
|
|
|
|
+
|
|
#endif /* __KERNEL__ */
|
|
#endif /* __KERNEL__ */
|
|
#endif /* _LINUX_SUNRPC_AUTH_H */
|
|
#endif /* _LINUX_SUNRPC_AUTH_H */
|