KEYS: Add an RCU payload dereference macro
authorDavid Howells <dhowells@redhat.com>
Mon, 7 Mar 2011 15:05:51 +0000 (15:05 +0000)
committerJames Morris <jmorris@namei.org>
Tue, 8 Mar 2011 00:17:11 +0000 (11:17 +1100)
Add an RCU payload dereference macro as this seems to be a common piece of code
amongst key types that use RCU referenced payloads.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
include/linux/key.h
security/keys/encrypted.c
security/keys/trusted.c
security/keys/user_defined.c

index 3db0adce1fdabd00d034ad2e111b9d3411146dfd..a6b1edcffc34e9a799d4b45b7fa933c756554511 100644 (file)
@@ -275,6 +275,10 @@ static inline key_serial_t key_serial(struct key *key)
        return key ? key->serial : 0;
 }
 
+#define rcu_dereference_key(KEY)                                       \
+       (rcu_dereference_protected((KEY)->payload.rcudata,              \
+                                  rwsem_is_locked(&((struct key *)(KEY))->sem)))
+
 #ifdef CONFIG_SYSCTL
 extern ctl_table key_sysctls[];
 #endif
index 9e7e4ce3fae820ec55cd64d9932ba1559372cb36..69907a58a6837d038675e55b6abede4176b92daf 100644 (file)
@@ -765,8 +765,7 @@ static long encrypted_read(const struct key *key, char __user *buffer,
        size_t asciiblob_len;
        int ret;
 
-       epayload = rcu_dereference_protected(key->payload.data,
-                                 rwsem_is_locked(&((struct key *)key)->sem));
+       epayload = rcu_dereference_key(key);
 
        /* returns the hex encoded iv, encrypted-data, and hmac as ascii */
        asciiblob_len = epayload->datablob_len + ivsize + 1
index 83fc92e297cd2257a26c6cbeeaca2b0588deac4f..c99b9368368c3d6e2193e81abaf5ab417d34557b 100644 (file)
@@ -1076,8 +1076,7 @@ static long trusted_read(const struct key *key, char __user *buffer,
        char *bufp;
        int i;
 
-       p = rcu_dereference_protected(key->payload.data,
-                       rwsem_is_locked(&((struct key *)key)->sem));
+       p = rcu_dereference_key(key);
        if (!p)
                return -EINVAL;
        if (!buffer || buflen <= 0)
index 02807fb163401bcbc9ff5cfc74bd6576b06ec918..c6ca8662a4685bd162205938eafae39bef25fbbf 100644 (file)
@@ -184,8 +184,7 @@ long user_read(const struct key *key, char __user *buffer, size_t buflen)
        struct user_key_payload *upayload;
        long ret;
 
-       upayload = rcu_dereference_protected(
-               key->payload.data, rwsem_is_locked(&((struct key *)key)->sem));
+       upayload = rcu_dereference_key(key);
        ret = upayload->datalen;
 
        /* we can return the data as is */