From 8c87553e2db672254d858991c42964030ad7da45 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 22 Oct 2023 01:10:42 -0700 Subject: [PATCH] crypto: starfive - remove unnecessary alignmask for ahashes The crypto API's support for alignmasks for ahash algorithms is nearly useless, as its only effect is to cause the API to align the key and result buffers. The drivers that happen to be specifying an alignmask for ahash rarely actually need it. When they do, it's easily fixable, especially considering that these buffers cannot be used for DMA. In preparation for removing alignmask support from ahash, this patch makes the starfive driver no longer use it. This driver did actually rely on it, but only for storing to the result buffer using int stores in starfive_hash_copy_hash(). This patch makes starfive_hash_copy_hash() use put_unaligned() instead. (It really should use a specific endianness, but that's an existing bug.) Signed-off-by: Eric Biggers Signed-off-by: Herbert Xu --- drivers/crypto/starfive/jh7110-hash.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/starfive/jh7110-hash.c b/drivers/crypto/starfive/jh7110-hash.c index cc7650198d70..b6d1808012ca 100644 --- a/drivers/crypto/starfive/jh7110-hash.c +++ b/drivers/crypto/starfive/jh7110-hash.c @@ -209,7 +209,8 @@ static int starfive_hash_copy_hash(struct ahash_request *req) data = (u32 *)req->result; for (count = 0; count < mlen; count++) - data[count] = readl(ctx->cryp->base + STARFIVE_HASH_SHARDR); + put_unaligned(readl(ctx->cryp->base + STARFIVE_HASH_SHARDR), + &data[count]); return 0; } @@ -628,7 +629,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SHA224_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } }, @@ -658,7 +658,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SHA224_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } }, @@ -687,7 +686,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SHA256_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } }, @@ -717,7 +715,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SHA256_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } }, @@ -746,7 +743,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SHA384_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } }, @@ -776,7 +772,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SHA384_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } }, @@ -805,7 +800,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SHA512_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } }, @@ -835,7 +829,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SHA512_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } }, @@ -864,7 +857,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SM3_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } }, @@ -894,7 +886,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = { CRYPTO_ALG_NEED_FALLBACK, .cra_blocksize = SM3_BLOCK_SIZE, .cra_ctxsize = sizeof(struct starfive_cryp_ctx), - .cra_alignmask = 3, .cra_module = THIS_MODULE, } },