Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: safexcel - Use crypto_wait_req

This patch replaces the custom crypto completion function with
crypto_req_done.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+24 -68
-11
drivers/crypto/inside-secure/safexcel.c
··· 970 970 } while (!cdesc->last_seg); 971 971 } 972 972 973 - void safexcel_inv_complete(struct crypto_async_request *req, int error) 974 - { 975 - struct safexcel_inv_result *result = req->data; 976 - 977 - if (error == -EINPROGRESS) 978 - return; 979 - 980 - result->error = error; 981 - complete(&result->completion); 982 - } 983 - 984 973 int safexcel_invalidate_cache(struct crypto_async_request *async, 985 974 struct safexcel_crypto_priv *priv, 986 975 dma_addr_t ctxr_dma, int ring)
-6
drivers/crypto/inside-secure/safexcel.h
··· 884 884 } alg; 885 885 }; 886 886 887 - struct safexcel_inv_result { 888 - struct completion completion; 889 - int error; 890 - }; 891 - 892 887 void safexcel_dequeue(struct safexcel_crypto_priv *priv, int ring); 893 888 int safexcel_rdesc_check_errors(struct safexcel_crypto_priv *priv, 894 889 void *rdp); ··· 922 927 struct crypto_async_request *req); 923 928 inline struct crypto_async_request * 924 929 safexcel_rdr_req_get(struct safexcel_crypto_priv *priv, int ring); 925 - void safexcel_inv_complete(struct crypto_async_request *req, int error); 926 930 int safexcel_hmac_setkey(struct safexcel_context *base, const u8 *key, 927 931 unsigned int keylen, const char *alg, 928 932 unsigned int state_sz);
+10 -11
drivers/crypto/inside-secure/safexcel_cipher.c
··· 1091 1091 static int safexcel_cipher_exit_inv(struct crypto_tfm *tfm, 1092 1092 struct crypto_async_request *base, 1093 1093 struct safexcel_cipher_req *sreq, 1094 - struct safexcel_inv_result *result) 1094 + struct crypto_wait *result) 1095 1095 { 1096 1096 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm); 1097 1097 struct safexcel_crypto_priv *priv = ctx->base.priv; 1098 1098 int ring = ctx->base.ring; 1099 - 1100 - init_completion(&result->completion); 1099 + int err; 1101 1100 1102 1101 ctx = crypto_tfm_ctx(base->tfm); 1103 1102 ctx->base.exit_inv = true; ··· 1109 1110 queue_work(priv->ring[ring].workqueue, 1110 1111 &priv->ring[ring].work_data.work); 1111 1112 1112 - wait_for_completion(&result->completion); 1113 + err = crypto_wait_req(-EINPROGRESS, result); 1113 1114 1114 - if (result->error) { 1115 + if (err) { 1115 1116 dev_warn(priv->dev, 1116 1117 "cipher: sync: invalidate: completion error %d\n", 1117 - result->error); 1118 - return result->error; 1118 + err); 1119 + return err; 1119 1120 } 1120 1121 1121 1122 return 0; ··· 1125 1126 { 1126 1127 EIP197_REQUEST_ON_STACK(req, skcipher, EIP197_SKCIPHER_REQ_SIZE); 1127 1128 struct safexcel_cipher_req *sreq = skcipher_request_ctx(req); 1128 - struct safexcel_inv_result result = {}; 1129 + DECLARE_CRYPTO_WAIT(result); 1129 1130 1130 1131 memset(req, 0, sizeof(struct skcipher_request)); 1131 1132 1132 1133 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 1133 - safexcel_inv_complete, &result); 1134 + crypto_req_done, &result); 1134 1135 skcipher_request_set_tfm(req, __crypto_skcipher_cast(tfm)); 1135 1136 1136 1137 return safexcel_cipher_exit_inv(tfm, &req->base, sreq, &result); ··· 1140 1141 { 1141 1142 EIP197_REQUEST_ON_STACK(req, aead, EIP197_AEAD_REQ_SIZE); 1142 1143 struct safexcel_cipher_req *sreq = aead_request_ctx(req); 1143 - struct safexcel_inv_result result = {}; 1144 + DECLARE_CRYPTO_WAIT(result); 1144 1145 1145 1146 memset(req, 0, sizeof(struct aead_request)); 1146 1147 1147 1148 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 1148 - safexcel_inv_complete, &result); 1149 + crypto_req_done, &result); 1149 1150 aead_request_set_tfm(req, __crypto_aead_cast(tfm)); 1150 1151 1151 1152 return safexcel_cipher_exit_inv(tfm, &req->base, sreq, &result);
+14 -40
drivers/crypto/inside-secure/safexcel_hash.c
··· 625 625 struct safexcel_crypto_priv *priv = ctx->base.priv; 626 626 EIP197_REQUEST_ON_STACK(req, ahash, EIP197_AHASH_REQ_SIZE); 627 627 struct safexcel_ahash_req *rctx = ahash_request_ctx_dma(req); 628 - struct safexcel_inv_result result = {}; 628 + DECLARE_CRYPTO_WAIT(result); 629 629 int ring = ctx->base.ring; 630 + int err; 630 631 631 632 memset(req, 0, EIP197_AHASH_REQ_SIZE); 632 633 633 634 /* create invalidation request */ 634 635 init_completion(&result.completion); 635 636 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 636 - safexcel_inv_complete, &result); 637 + crypto_req_done, &result); 637 638 638 639 ahash_request_set_tfm(req, __crypto_ahash_cast(tfm)); 639 640 ctx = crypto_tfm_ctx(req->base.tfm); ··· 648 647 queue_work(priv->ring[ring].workqueue, 649 648 &priv->ring[ring].work_data.work); 650 649 651 - wait_for_completion(&result.completion); 650 + err = crypto_wait_req(-EINPROGRESS, &result); 652 651 653 - if (result.error) { 654 - dev_warn(priv->dev, "hash: completion error (%d)\n", 655 - result.error); 656 - return result.error; 652 + if (err) { 653 + dev_warn(priv->dev, "hash: completion error (%d)\n", err); 654 + return err; 657 655 } 658 656 659 657 return 0; ··· 1042 1042 return safexcel_ahash_finup(areq); 1043 1043 } 1044 1044 1045 - struct safexcel_ahash_result { 1046 - struct completion completion; 1047 - int error; 1048 - }; 1049 - 1050 - static void safexcel_ahash_complete(struct crypto_async_request *req, int error) 1051 - { 1052 - struct safexcel_ahash_result *result = req->data; 1053 - 1054 - if (error == -EINPROGRESS) 1055 - return; 1056 - 1057 - result->error = error; 1058 - complete(&result->completion); 1059 - } 1060 - 1061 1045 static int safexcel_hmac_init_pad(struct ahash_request *areq, 1062 1046 unsigned int blocksize, const u8 *key, 1063 1047 unsigned int keylen, u8 *ipad, u8 *opad) 1064 1048 { 1065 - struct safexcel_ahash_result result; 1049 + DECLARE_CRYPTO_WAIT(result); 1066 1050 struct scatterlist sg; 1067 1051 int ret, i; 1068 1052 u8 *keydup; ··· 1059 1075 return -ENOMEM; 1060 1076 1061 1077 ahash_request_set_callback(areq, CRYPTO_TFM_REQ_MAY_BACKLOG, 1062 - safexcel_ahash_complete, &result); 1078 + crypto_req_done, &result); 1063 1079 sg_init_one(&sg, keydup, keylen); 1064 1080 ahash_request_set_crypt(areq, &sg, ipad, keylen); 1065 - init_completion(&result.completion); 1066 1081 1067 1082 ret = crypto_ahash_digest(areq); 1068 - if (ret == -EINPROGRESS || ret == -EBUSY) { 1069 - wait_for_completion_interruptible(&result.completion); 1070 - ret = result.error; 1071 - } 1083 + ret = crypto_wait_req(ret, &result); 1072 1084 1073 1085 /* Avoid leaking */ 1074 1086 kfree_sensitive(keydup); ··· 1089 1109 static int safexcel_hmac_init_iv(struct ahash_request *areq, 1090 1110 unsigned int blocksize, u8 *pad, void *state) 1091 1111 { 1092 - struct safexcel_ahash_result result; 1093 1112 struct safexcel_ahash_req *req; 1113 + DECLARE_CRYPTO_WAIT(result); 1094 1114 struct scatterlist sg; 1095 1115 int ret; 1096 1116 1097 1117 ahash_request_set_callback(areq, CRYPTO_TFM_REQ_MAY_BACKLOG, 1098 - safexcel_ahash_complete, &result); 1118 + crypto_req_done, &result); 1099 1119 sg_init_one(&sg, pad, blocksize); 1100 1120 ahash_request_set_crypt(areq, &sg, pad, blocksize); 1101 - init_completion(&result.completion); 1102 1121 1103 1122 ret = crypto_ahash_init(areq); 1104 1123 if (ret) ··· 1108 1129 req->last_req = true; 1109 1130 1110 1131 ret = crypto_ahash_update(areq); 1111 - if (ret && ret != -EINPROGRESS && ret != -EBUSY) 1112 - return ret; 1132 + ret = crypto_wait_req(ret, &result); 1113 1133 1114 - wait_for_completion_interruptible(&result.completion); 1115 - if (result.error) 1116 - return result.error; 1117 - 1118 - return crypto_ahash_export(areq, state); 1134 + return ret ?: crypto_ahash_export(areq, state); 1119 1135 } 1120 1136 1121 1137 static int __safexcel_hmac_setkey(const char *alg, const u8 *key,