From c7915b5bd657e7e86caed1fe34e4fa2278769285 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 7 Aug 2010 03:16:36 +0200 Subject: Use a struct mutex for session_item_st.mem_mutex Suggested by scripts/checkpatch.pl --- ncr-int.h | 3 ++- ncr-sessions.c | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ncr-int.h b/ncr-int.h index e79747c12ca..06c5e62d092 100644 --- a/ncr-int.h +++ b/ncr-int.h @@ -1,6 +1,7 @@ #ifndef NCR_INT_H # define NCR_INT_H +#include #include "ncr.h" #include #include "cryptodev_int.h" @@ -48,7 +49,7 @@ struct session_item_st { struct page **pages; unsigned array_size; unsigned available_pages; - struct semaphore mem_mutex; /* down when the + struct mutex mem_mutex; /* down when the * values above are changed. */ diff --git a/ncr-sessions.c b/ncr-sessions.c index 365935fe2bf..09016188531 100644 --- a/ncr-sessions.c +++ b/ncr-sessions.c @@ -24,6 +24,7 @@ */ #include +#include #include "cryptodev.h" #include "ncr.h" #include "ncr-int.h" @@ -119,7 +120,7 @@ struct session_item_st* ncr_session_new(struct list_sem_st* lst) kfree(sess); return NULL; } - init_MUTEX(&sess->mem_mutex); + mutex_init(&sess->mem_mutex); atomic_set(&sess->refcnt, 2); /* One for lst->list, one for "sess" */ @@ -636,7 +637,7 @@ static int _ncr_session_update(struct ncr_lists* lists, struct ncr_session_op_st return -EINVAL; } - if (down_interruptible(&sess->mem_mutex)) { + if (mutex_lock_interruptible(&sess->mem_mutex)) { err(); _ncr_sessions_item_put(sess); return -ERESTARTSYS; @@ -717,7 +718,7 @@ fail: release_user_pages(sess->pages, sess->available_pages); sess->available_pages = 0; } - up(&sess->mem_mutex); + mutex_unlock(&sess->mem_mutex); _ncr_sessions_item_put(sess); return ret; @@ -763,7 +764,7 @@ static int _ncr_session_final(struct ncr_lists* lists, struct ncr_session_op_st* return ret; } - if (down_interruptible(&sess->mem_mutex)) { + if (mutex_lock_interruptible(&sess->mem_mutex)) { err(); _ncr_sessions_item_put(sess); return -ERESTARTSYS; @@ -890,7 +891,7 @@ fail: release_user_pages(sess->pages, sess->available_pages); sess->available_pages = 0; } - up(&sess->mem_mutex); + mutex_unlock(&sess->mem_mutex); cryptodev_hash_deinit(&sess->hash); if (sess->algorithm->is_symmetric) { -- cgit From 861078d0afcb65d7a03780d9a5603dae5fec82b9 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 7 Aug 2010 03:18:37 +0200 Subject: Make cryptodev_fops const. Suggested by scripts/checkpatch.pl. --- cryptodev_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptodev_main.c b/cryptodev_main.c index 3223acd1e72..a303bbb337b 100644 --- a/cryptodev_main.c +++ b/cryptodev_main.c @@ -951,7 +951,7 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_) #endif /* CONFIG_COMPAT */ -static struct file_operations cryptodev_fops = { +static const struct file_operations cryptodev_fops = { .owner = THIS_MODULE, .open = cryptodev_open, .release = cryptodev_release, -- cgit From 09966a1c51fe61490c7b5932db1e7ad5c299ca2f Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 7 Aug 2010 03:22:13 +0200 Subject: Use instead of Suggested by scripts/checkpatch.pl. --- cryptodev_cipher.c | 2 +- cryptodev_main.c | 2 +- ncr-dh.c | 2 +- ncr-key-storage.c | 2 +- ncr-key-wrap.c | 2 +- ncr-key.c | 2 +- ncr-pk.c | 2 +- ncr.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cryptodev_cipher.c b/cryptodev_cipher.c index 01dc29dc7cc..2df7259f408 100644 --- a/cryptodev_cipher.c +++ b/cryptodev_cipher.c @@ -25,9 +25,9 @@ #include #include #include +#include #include #include -#include #include #include #include diff --git a/cryptodev_main.c b/cryptodev_main.c index a303bbb337b..62a3f1bf178 100644 --- a/cryptodev_main.c +++ b/cryptodev_main.c @@ -34,12 +34,12 @@ #include #include #include +#include #include #include #include #include "cryptodev.h" #include -#include #include #include "cryptodev_int.h" #include "ncr-int.h" diff --git a/ncr-dh.c b/ncr-dh.c index cad4d4c6dc2..5275e34f30e 100644 --- a/ncr-dh.c +++ b/ncr-dh.c @@ -22,12 +22,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include #include #include "cryptodev.h" #include -#include #include #include #include diff --git a/ncr-key-storage.c b/ncr-key-storage.c index 41e52b77638..c78dcee6ced 100644 --- a/ncr-key-storage.c +++ b/ncr-key-storage.c @@ -22,11 +22,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include #include "cryptodev.h" #include -#include #include #include "ncr.h" #include "ncr-int.h" diff --git a/ncr-key-wrap.c b/ncr-key-wrap.c index fda8de2c6e7..776fe66e8bd 100644 --- a/ncr-key-wrap.c +++ b/ncr-key-wrap.c @@ -22,13 +22,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include #include #include #include "cryptodev.h" #include -#include #include #include "ncr.h" #include "ncr-int.h" diff --git a/ncr-key.c b/ncr-key.c index 40767c4ad1f..835dfcdd7c9 100644 --- a/ncr-key.c +++ b/ncr-key.c @@ -22,12 +22,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include #include #include "cryptodev.h" #include -#include #include #include "ncr.h" #include "ncr-int.h" diff --git a/ncr-pk.c b/ncr-pk.c index fece4ece815..0ecbe335718 100644 --- a/ncr-pk.c +++ b/ncr-pk.c @@ -22,12 +22,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include #include #include "cryptodev.h" #include -#include #include #include "ncr.h" #include "ncr-int.h" diff --git a/ncr.c b/ncr.c index 7608312ed7b..cc9696b7995 100644 --- a/ncr.c +++ b/ncr.c @@ -23,12 +23,12 @@ */ #include +#include #include #include #include #include "cryptodev.h" #include -#include #include #include #include -- cgit From cb519ef9fc39d3ccb1272ec7685524443490ca54 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 7 Aug 2010 03:25:00 +0200 Subject: Use instead of Suggested by scripts/checkpatch.pl. --- cryptodev_cipher.c | 2 +- cryptodev_main.c | 2 +- ncr-dh.c | 2 +- ncr-key-storage.c | 2 +- ncr-key-wrap.c | 2 +- ncr-key.c | 2 +- ncr-pk.c | 2 +- ncr.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cryptodev_cipher.c b/cryptodev_cipher.c index 2df7259f408..832202789b6 100644 --- a/cryptodev_cipher.c +++ b/cryptodev_cipher.c @@ -27,8 +27,8 @@ #include #include #include -#include #include +#include #include #include #include "cryptodev.h" diff --git a/cryptodev_main.c b/cryptodev_main.c index 62a3f1bf178..a056b447731 100644 --- a/cryptodev_main.c +++ b/cryptodev_main.c @@ -38,8 +38,8 @@ #include #include #include +#include #include "cryptodev.h" -#include #include #include "cryptodev_int.h" #include "ncr-int.h" diff --git a/ncr-dh.c b/ncr-dh.c index 5275e34f30e..235d021fae4 100644 --- a/ncr-dh.c +++ b/ncr-dh.c @@ -26,8 +26,8 @@ #include #include #include +#include #include "cryptodev.h" -#include #include #include #include diff --git a/ncr-key-storage.c b/ncr-key-storage.c index c78dcee6ced..fc6948f5c61 100644 --- a/ncr-key-storage.c +++ b/ncr-key-storage.c @@ -25,8 +25,8 @@ #include #include #include +#include #include "cryptodev.h" -#include #include #include "ncr.h" #include "ncr-int.h" diff --git a/ncr-key-wrap.c b/ncr-key-wrap.c index 776fe66e8bd..e3b1de534d5 100644 --- a/ncr-key-wrap.c +++ b/ncr-key-wrap.c @@ -27,8 +27,8 @@ #include #include #include +#include #include "cryptodev.h" -#include #include #include "ncr.h" #include "ncr-int.h" diff --git a/ncr-key.c b/ncr-key.c index 835dfcdd7c9..20a998f8a2a 100644 --- a/ncr-key.c +++ b/ncr-key.c @@ -26,8 +26,8 @@ #include #include #include +#include #include "cryptodev.h" -#include #include #include "ncr.h" #include "ncr-int.h" diff --git a/ncr-pk.c b/ncr-pk.c index 0ecbe335718..392ff077529 100644 --- a/ncr-pk.c +++ b/ncr-pk.c @@ -26,8 +26,8 @@ #include #include #include +#include #include "cryptodev.h" -#include #include #include "ncr.h" #include "ncr-int.h" diff --git a/ncr.c b/ncr.c index cc9696b7995..1cbe2158070 100644 --- a/ncr.c +++ b/ncr.c @@ -27,8 +27,8 @@ #include #include #include +#include #include "cryptodev.h" -#include #include #include #include -- cgit From f28aa3e7b3a1cd96f5e6449e3793561409f1ac94 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sun, 8 Aug 2010 02:03:13 +0200 Subject: Use types from for public headers. When included in the kernel tree, is not available, so has to be used. does not provide the uintNN_t and size_t types when installed to /usr/include/linux (package kernel-headers on Fedora). Therefore, use the types from that are available in userspace. Also fix user-space users of the headers not to assume that they provide the types. --- cryptodev.h | 53 ++++++++++++++++++++++++++--------------------------- examples/cipher.c | 1 + examples/hmac.c | 1 + examples/ncr.c | 1 + examples/pk.c | 1 + ncr.h | 44 +++++++++++++++++++++++--------------------- userspace/setkey.c | 1 + 7 files changed, 54 insertions(+), 48 deletions(-) diff --git a/cryptodev.h b/cryptodev.h index 4d6b712e506..4a546b88d2d 100644 --- a/cryptodev.h +++ b/cryptodev.h @@ -5,10 +5,9 @@ #ifndef L_CRYPTODEV_H #define L_CRYPTODEV_H +#include #ifndef __KERNEL__ -#include #define __user -#else #endif /* API extensions for linux */ @@ -71,15 +70,15 @@ typedef enum { struct session_op { /* Specify either cipher or mac */ - uint32_t cipher; /* cryptodev_crypto_op_t */ - uint32_t mac; /* cryptodev_crypto_op_t */ + __u32 cipher; /* cryptodev_crypto_op_t */ + __u32 mac; /* cryptodev_crypto_op_t */ - uint32_t keylen; - uint8_t __user *key; - uint32_t mackeylen; - uint8_t __user *mackey; + __u32 keylen; + __u8 __user *key; + __u32 mackeylen; + __u8 __user *mackey; - uint32_t ses; /* session identifier */ + __u32 ses; /* session identifier */ }; #define COP_ENCRYPT 0 @@ -87,14 +86,14 @@ struct session_op { /* input of CIOCCRYPT */ struct crypt_op { - uint32_t ses; /* session identifier */ - uint16_t op; /* COP_ENCRYPT or COP_DECRYPT */ - uint16_t flags; /* no usage so far, use 0 */ - uint32_t len; /* length of source data */ - uint8_t __user *src; /* source data */ - uint8_t __user *dst; /* pointer to output data */ - uint8_t __user *mac; /* pointer to output data for hash/MAC operations */ - uint8_t __user *iv; /* initialization vector for encryption operations */ + __u32 ses; /* session identifier */ + __u16 op; /* COP_ENCRYPT or COP_DECRYPT */ + __u16 flags; /* no usage so far, use 0 */ + __u32 len; /* length of source data */ + __u8 __user *src; /* source data */ + __u8 __user *dst; /* pointer to output data */ + __u8 __user *mac; /* pointer to output data for hash/MAC operations */ + __u8 __user *iv; /* initialization vector for encryption operations */ }; /* Stuff for bignum arithmetic and public key @@ -107,19 +106,19 @@ struct session_op { #define CRYPTO_ALG_FLAG_DSA_SHA 4 struct crparam { - uint8_t* crp_p; - uint32_t crp_nbits; + __u8* crp_p; + __u32 crp_nbits; }; #define CRK_MAXPARAM 8 /* input of CIOCKEY */ struct crypt_kop { - uint32_t crk_op; /* cryptodev_crk_ot_t */ - uint32_t crk_status; - uint16_t crk_iparams; - uint16_t crk_oparams; - uint32_t crk_pad1; + __u32 crk_op; /* cryptodev_crk_ot_t */ + __u32 crk_status; + __u16 crk_iparams; + __u16 crk_oparams; + __u32 crk_pad1; struct crparam crk_param[CRK_MAXPARAM]; }; @@ -145,11 +144,11 @@ typedef enum { /* ioctl's. Compatible with old linux cryptodev.h */ -#define CRIOGET _IOWR('c', 101, uint32_t) +#define CRIOGET _IOWR('c', 101, __u32) #define CIOCGSESSION _IOWR('c', 102, struct session_op) -#define CIOCFSESSION _IOW('c', 103, uint32_t) +#define CIOCFSESSION _IOW('c', 103, __u32) #define CIOCCRYPT _IOWR('c', 104, struct crypt_op) #define CIOCKEY _IOWR('c', 105, struct crypt_kop) -#define CIOCASYMFEAT _IOR('c', 106, uint32_t) +#define CIOCASYMFEAT _IOR('c', 106, __u32) #endif /* L_CRYPTODEV_H */ diff --git a/examples/cipher.c b/examples/cipher.c index 1334f02304c..52b4996f4a6 100644 --- a/examples/cipher.c +++ b/examples/cipher.c @@ -4,6 +4,7 @@ * Placed under public domain. * */ +#include #include #include #include diff --git a/examples/hmac.c b/examples/hmac.c index 9757f901ae9..c54d7419a34 100644 --- a/examples/hmac.c +++ b/examples/hmac.c @@ -4,6 +4,7 @@ * Placed under public domain. * */ +#include #include #include #include diff --git a/examples/ncr.c b/examples/ncr.c index 4231ffa5681..9a75a996e58 100644 --- a/examples/ncr.c +++ b/examples/ncr.c @@ -4,6 +4,7 @@ * Placed under public domain. * */ +#include #include #include #include diff --git a/examples/pk.c b/examples/pk.c index 69450b12cea..3102a3b1abd 100644 --- a/examples/pk.c +++ b/examples/pk.c @@ -4,6 +4,7 @@ * Placed under public domain. * */ +#include #include #include #include diff --git a/ncr.h b/ncr.h index 53c77be865f..9603d03586c 100644 --- a/ncr.h +++ b/ncr.h @@ -1,8 +1,8 @@ #ifndef L_NCR_H #define L_NCR_H +#include #ifndef __KERNEL__ -#include #define __user #endif @@ -96,10 +96,10 @@ struct ncr_key_generate_params_st { unsigned int q_bits; } dsa; struct { - uint8_t __user *p; /* prime */ - size_t p_size; - uint8_t __user *g; /* generator */ - size_t g_size; + __u8 __user *p; /* prime */ + __kernel_size_t p_size; + __u8 __user *g; /* generator */ + __kernel_size_t g_size; } dh; } params; }; @@ -126,12 +126,12 @@ struct ncr_key_params_st { * key */ union { struct { - uint8_t iv[NCR_CIPHER_MAX_BLOCK_LEN]; - size_t iv_size; + __u8 iv[NCR_CIPHER_MAX_BLOCK_LEN]; + __kernel_size_t iv_size; } cipher; struct { - uint8_t __user *pub; - size_t pub_size; + __u8 __user *pub; + __kernel_size_t pub_size; } dh; struct { ncr_rsa_type_t type; @@ -168,19 +168,19 @@ struct ncr_key_info_st { ncr_key_type_t type; ncr_algorithm_t algorithm; /* valid for public/private keys */ - uint8_t key_id[MAX_KEY_ID_SIZE]; - size_t key_id_size; + __u8 key_id[MAX_KEY_ID_SIZE]; + __kernel_size_t key_id_size; }; struct ncr_key_data_st { ncr_key_t key; void __user *idata; - size_t idata_size; /* rw in get */ + __kernel_size_t idata_size; /* rw in get */ /* in case of import this will be used as key id */ - uint8_t key_id[MAX_KEY_ID_SIZE]; - size_t key_id_size; + __u8 key_id[MAX_KEY_ID_SIZE]; + __kernel_size_t key_id_size; ncr_key_type_t type; unsigned int flags; ncr_algorithm_t algorithm; /* valid for public/private keys */ @@ -212,7 +212,8 @@ struct ncr_key_wrap_st { struct ncr_key_params_st params; void __user * io; /* encrypted keytowrap */ - size_t io_size; /* this will be updated by the actual size on wrap */ + /* this will be updated by the actual size on wrap */ + __kernel_size_t io_size; }; #define NCRIO_KEY_WRAP _IOWR ('c', 250, struct ncr_key_wrap_st) @@ -220,8 +221,8 @@ struct ncr_key_wrap_st { /* Internal ops */ struct ncr_master_key_st { - uint8_t __user * key; - uint16_t key_size; + __u8 __user * key; + __u16 key_size; }; #define NCRIO_MASTER_KEY_SET _IOR ('c', 260, struct ncr_master_key_st) @@ -232,7 +233,8 @@ struct ncr_key_storage_wrap_st { ncr_key_t keytowrap; void __user * io; /* encrypted keytowrap */ - size_t io_size; /* this will be updated by the actual size on wrap */ + /* this will be updated by the actual size on wrap */ + __kernel_size_t io_size; }; #define NCRIO_KEY_STORAGE_WRAP _IOWR ('c', 261, struct ncr_key_storage_wrap_st) @@ -285,13 +287,13 @@ struct ncr_session_op_st { void __user * output; /* when verifying signature this is * the place of the signature. */ - size_t output_size; + __kernel_size_t output_size; } kdata; /* NCR_KEY_DATA */ struct { void __user * input; - size_t input_size; + __kernel_size_t input_size; void __user * output; - size_t output_size; + __kernel_size_t output_size; } udata; /* NCR_DIRECT_DATA */ } data; ncr_data_type_t type; diff --git a/userspace/setkey.c b/userspace/setkey.c index ea9d30ea684..b090bd50306 100644 --- a/userspace/setkey.c +++ b/userspace/setkey.c @@ -4,6 +4,7 @@ * Placed under public domain. * */ +#include #include #include #include -- cgit