Skip to content

Commit 65055e2

Browse files
lenormandfranckherbertx
authored andcommitted
crypto: caam - fix hash context DMA unmap size
When driver started using state->caam_ctxt for storing both running hash and final hash, it was not updated to handle different DMA unmap lengths. Cc: <stable@vger.kernel.org> # v4.19+ Fixes: c19650d ("crypto: caam - fix DMA mapping of stack memory") Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com> Signed-off-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 984798d commit 65055e2

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎drivers/crypto/caam/caamhash.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct caam_hash_ctx {
114114
struct caam_hash_state {
115115
dma_addr_t buf_dma;
116116
dma_addr_t ctx_dma;
117+
int ctx_dma_len;
117118
u8 buf_0[CAAM_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned;
118119
int buflen_0;
119120
u8 buf_1[CAAM_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned;
@@ -171,6 +172,7 @@ static inline int map_seq_out_ptr_ctx(u32 *desc, struct device *jrdev,
171172
struct caam_hash_state *state,
172173
int ctx_len)
173174
{
175+
state->ctx_dma_len = ctx_len;
174176
state->ctx_dma = dma_map_single(jrdev, state->caam_ctx,
175177
ctx_len, DMA_FROM_DEVICE);
176178
if (dma_mapping_error(jrdev, state->ctx_dma)) {
@@ -212,6 +214,7 @@ static inline int ctx_map_to_sec4_sg(struct device *jrdev,
212214
struct caam_hash_state *state, int ctx_len,
213215
struct sec4_sg_entry *sec4_sg, u32 flag)
214216
{
217+
state->ctx_dma_len = ctx_len;
215218
state->ctx_dma = dma_map_single(jrdev, state->caam_ctx, ctx_len, flag);
216219
if (dma_mapping_error(jrdev, state->ctx_dma)) {
217220
dev_err(jrdev, "unable to map ctx\n");
@@ -594,12 +597,10 @@ static inline void ahash_unmap_ctx(struct device *dev,
594597
struct ahash_edesc *edesc,
595598
struct ahash_request *req, int dst_len, u32 flag)
596599
{
597-
struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
598-
struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
599600
struct caam_hash_state *state = ahash_request_ctx(req);
600601

601602
if (state->ctx_dma) {
602-
dma_unmap_single(dev, state->ctx_dma, ctx->ctx_len, flag);
603+
dma_unmap_single(dev, state->ctx_dma, state->ctx_dma_len, flag);
603604
state->ctx_dma = 0;
604605
}
605606
ahash_unmap(dev, edesc, req, dst_len);
@@ -1580,6 +1581,7 @@ static int ahash_init(struct ahash_request *req)
15801581
state->final = ahash_final_no_ctx;
15811582

15821583
state->ctx_dma = 0;
1584+
state->ctx_dma_len = 0;
15831585
state->current_buf = 0;
15841586
state->buf_dma = 0;
15851587
state->buflen_0 = 0;

0 commit comments

Comments
 (0)