]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-5.1/crypto-caam-qi2-fix-zero-length-buffer-dma-mapping.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / queue-5.1 / crypto-caam-qi2-fix-zero-length-buffer-dma-mapping.patch
CommitLineData
d6f9e419
GKH
1From 07586d3ddf284dd7a1a6579579d8efa7296fe60f Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Horia=20Geant=C4=83?= <horia.geanta@nxp.com>
3Date: Thu, 25 Apr 2019 17:52:21 +0300
4Subject: crypto: caam/qi2 - fix zero-length buffer DMA mapping
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9From: Horia Geantă <horia.geanta@nxp.com>
10
11commit 07586d3ddf284dd7a1a6579579d8efa7296fe60f upstream.
12
13Commit 04e6d25c5bb2 ("crypto: caam - fix zero-length buffer DMA mapping")
14fixed an issue in caam/jr driver where ahash implementation was
15DMA mapping a zero-length buffer.
16
17Current commit applies a similar fix for caam/qi2 driver.
18
19Cc: <stable@vger.kernel.org> # v4.20+
20Fixes: 3f16f6c9d632 ("crypto: caam/qi2 - add support for ahash algorithms")
21Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
22Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
23Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24
25---
26 drivers/crypto/caam/caamalg_qi2.c | 25 ++++++++++++++++++-------
27 1 file changed, 18 insertions(+), 7 deletions(-)
28
29--- a/drivers/crypto/caam/caamalg_qi2.c
30+++ b/drivers/crypto/caam/caamalg_qi2.c
31@@ -3755,10 +3755,13 @@ static int ahash_final_no_ctx(struct aha
32 if (!edesc)
33 return ret;
34
35- state->buf_dma = dma_map_single(ctx->dev, buf, buflen, DMA_TO_DEVICE);
36- if (dma_mapping_error(ctx->dev, state->buf_dma)) {
37- dev_err(ctx->dev, "unable to map src\n");
38- goto unmap;
39+ if (buflen) {
40+ state->buf_dma = dma_map_single(ctx->dev, buf, buflen,
41+ DMA_TO_DEVICE);
42+ if (dma_mapping_error(ctx->dev, state->buf_dma)) {
43+ dev_err(ctx->dev, "unable to map src\n");
44+ goto unmap;
45+ }
46 }
47
48 edesc->dst_dma = dma_map_single(ctx->dev, req->result, digestsize,
49@@ -3771,9 +3774,17 @@ static int ahash_final_no_ctx(struct aha
50
51 memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
52 dpaa2_fl_set_final(in_fle, true);
53- dpaa2_fl_set_format(in_fle, dpaa2_fl_single);
54- dpaa2_fl_set_addr(in_fle, state->buf_dma);
55- dpaa2_fl_set_len(in_fle, buflen);
56+ /*
57+ * crypto engine requires the input entry to be present when
58+ * "frame list" FD is used.
59+ * Since engine does not support FMT=2'b11 (unused entry type), leaving
60+ * in_fle zeroized (except for "Final" flag) is the best option.
61+ */
62+ if (buflen) {
63+ dpaa2_fl_set_format(in_fle, dpaa2_fl_single);
64+ dpaa2_fl_set_addr(in_fle, state->buf_dma);
65+ dpaa2_fl_set_len(in_fle, buflen);
66+ }
67 dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
68 dpaa2_fl_set_addr(out_fle, edesc->dst_dma);
69 dpaa2_fl_set_len(out_fle, digestsize);