diff options
-rw-r--r-- | cryptodev_cipher.c | 24 | ||||
-rw-r--r-- | cryptodev_main.c | 21 |
2 files changed, 23 insertions, 22 deletions
diff --git a/cryptodev_cipher.c b/cryptodev_cipher.c index 60a55db..d42bb2e 100644 --- a/cryptodev_cipher.c +++ b/cryptodev_cipher.c @@ -67,7 +67,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, uint8_t copy_from_user(keyp, key, keylen); out->async.s = crypto_alloc_ablkcipher(alg_name, 0, 0); - if (IS_ERR(out->async.s)) { + if (unlikely(IS_ERR(out->async.s))) { dprintk(1,KERN_DEBUG,"%s: Failed to load cipher %s\n", __func__, alg_name); return -EINVAL; @@ -77,8 +77,8 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, uint8_t if (alg != NULL) { /* Was correct key length supplied? */ - if ((keylen < alg->min_keysize) || - (keylen > alg->max_keysize)) { + if (unlikely((keylen < alg->min_keysize) || + (keylen > alg->max_keysize))) { dprintk(1,KERN_DEBUG,"Wrong keylen '%zu' for algorithm '%s'. Use %u to %u.\n", keylen, alg_name, alg->min_keysize, alg->max_keysize); @@ -88,7 +88,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, uint8_t } ret = crypto_ablkcipher_setkey(out->async.s, keyp, keylen); - if (ret) { + if (unlikely(ret)) { dprintk(1,KERN_DEBUG,"Setting key failed for %s-%zu.\n", alg_name, keylen*8); ret = -EINVAL; @@ -99,7 +99,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, uint8_t out->ivsize = crypto_ablkcipher_ivsize(out->async.s); out->async.result = kmalloc(sizeof(*out->async.result), GFP_KERNEL); - if (!out->async.result) { + if (unlikely(!out->async.result)) { ret = -ENOMEM; goto error; } @@ -108,7 +108,7 @@ int cryptodev_cipher_init(struct cipher_data* out, const char* alg_name, uint8_t init_completion(&out->async.result->completion); out->async.request = ablkcipher_request_alloc(out->async.s, GFP_KERNEL); - if (!out->async.request) { + if (unlikely(!out->async.request)) { dprintk(1,KERN_ERR,"error allocating async crypto request\n"); ret = -ENOMEM; goto error; @@ -154,7 +154,7 @@ static inline int waitfor (struct cryptodev_result* cr, ssize_t ret) * might try to access memory which will be freed or reused for * another request. */ - if (cr->err) { + if (unlikely(cr->err)) { dprintk(0,KERN_ERR,"error from async request: %zd \n", ret); return cr->err; } @@ -200,7 +200,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN]; hdata->init = 1; - if (mackeylen > CRYPTO_HMAC_MAX_KEY_LEN) { + if (unlikely(mackeylen > CRYPTO_HMAC_MAX_KEY_LEN)) { dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n", alg_name, mackeylen*8); return -EINVAL; @@ -208,7 +208,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN]; copy_from_user(hkeyp, mackey, mackeylen); hdata->async.s = crypto_alloc_ahash(alg_name, 0, 0); - if (IS_ERR(hdata->async.s)) { + if (unlikely(IS_ERR(hdata->async.s))) { dprintk(1,KERN_DEBUG,"%s: Failed to load transform for %s\n", __func__, alg_name); return -EINVAL; @@ -218,7 +218,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN]; if (hmac_mode != 0) { ret = crypto_ahash_setkey(hdata->async.s, hkeyp, mackeylen); - if (ret) { + if (unlikely(ret)) { dprintk(1,KERN_DEBUG,"Setting hmac key failed for %s-%zu.\n", alg_name, mackeylen*8); ret = -EINVAL; @@ -229,7 +229,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN]; hdata->digestsize = crypto_ahash_digestsize(hdata->async.s); hdata->async.result = kmalloc(sizeof(*hdata->async.result), GFP_KERNEL); - if (!hdata->async.result) { + if (unlikely(!hdata->async.result)) { ret = -ENOMEM; goto error; } @@ -238,7 +238,7 @@ uint8_t hkeyp[CRYPTO_HMAC_MAX_KEY_LEN]; init_completion(&hdata->async.result->completion); hdata->async.request = ahash_request_alloc(hdata->async.s, GFP_KERNEL); - if (!hdata->async.request) { + if (unlikely(!hdata->async.request)) { dprintk(0,KERN_ERR,"error allocating async crypto request\n"); ret = -ENOMEM; goto error; diff --git a/cryptodev_main.c b/cryptodev_main.c index 63ce162..5adbe40 100644 --- a/cryptodev_main.c +++ b/cryptodev_main.c @@ -26,8 +26,7 @@ * hashes) from userspace programs. * * /dev/crypto interface was originally introduced in - * OpenBSD and this module attempts to keep the API, - * although a bit extended. + * OpenBSD and this module attempts to keep the API. * */ @@ -102,7 +101,7 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop) int hmac_mode = 1; /* Does the request make sense? */ - if (!sop->cipher && !sop->mac) { + if (unlikely(!sop->cipher && !sop->mac)) { dprintk(1,KERN_DEBUG,"Both 'cipher' and 'mac' unset.\n"); return -EINVAL; } @@ -287,7 +286,7 @@ crypto_finish_session(struct fcrypt *fcr, uint32_t sid) } } - if (!ses_ptr) { + if (unlikely(!ses_ptr)) { dprintk(1, KERN_ERR, "Session with sid=0x%08X not found!\n", sid); ret = -ENOENT; } @@ -353,7 +352,7 @@ crypto_run(struct fcrypt *fcr, struct crypt_op *cop) } ses_ptr = crypto_get_session_by_sid(fcr, cop->ses); - if (!ses_ptr) { + if (unlikely(!ses_ptr)) { dprintk(1, KERN_ERR, "invalid session ID=0x%08X\n", cop->ses); return -EINVAL; } @@ -542,7 +541,7 @@ cryptodev_ioctl(struct inode *inode, struct file *filp, uint32_t ses; int ret, fd; - if (!fcr) + if (unlikely(!fcr)) BUG(); switch (cmd) { @@ -557,7 +556,7 @@ cryptodev_ioctl(struct inode *inode, struct file *filp, case CIOCGSESSION: copy_from_user(&sop, (void*)arg, sizeof(sop)); ret = crypto_create_session(fcr, &sop); - if (ret) + if (unlikely(ret)) return ret; copy_to_user((void*)arg, &sop, sizeof(sop)); return 0; @@ -570,8 +569,10 @@ cryptodev_ioctl(struct inode *inode, struct file *filp, case CIOCCRYPT: copy_from_user(&cop, (void*)arg, sizeof(cop)); ret = crypto_run(fcr, &cop); + if (unlikely(ret)) + return ret; copy_to_user((void*)arg, &cop, sizeof(cop)); - return ret; + return 0; default: return -EINVAL; @@ -597,7 +598,7 @@ cryptodev_register(void) int rc; rc = misc_register (&cryptodev); - if (rc) { + if (unlikely(rc)) { printk(KERN_ERR PFX "registeration of /dev/crypto failed\n"); return rc; } @@ -618,7 +619,7 @@ int __init init_cryptodev(void) int rc; rc = cryptodev_register(); - if (rc) + if (unlikely(rc)) return rc; printk(KERN_INFO PFX "driver loaded.\n"); |