diff options
| author | Horia Geantă <horia.geanta@nxp.com> | 2019-04-25 10:52:21 -0400 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2019-05-03 02:03:29 -0400 |
| commit | 07586d3ddf284dd7a1a6579579d8efa7296fe60f (patch) | |
| tree | 2db4041317beab512de72b2246984e74b7199548 | |
| parent | 5f49f18d27cd6d49c52f2805cd79c2362710a2e9 (diff) | |
crypto: caam/qi2 - fix zero-length buffer DMA mapping
Commit 04e6d25c5bb2 ("crypto: caam - fix zero-length buffer DMA mapping")
fixed an issue in caam/jr driver where ahash implementation was
DMA mapping a zero-length buffer.
Current commit applies a similar fix for caam/qi2 driver.
Cc: <stable@vger.kernel.org> # v4.20+
Fixes: 3f16f6c9d632 ("crypto: caam/qi2 - add support for ahash algorithms")
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
| -rw-r--r-- | drivers/crypto/caam/caamalg_qi2.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index d19c97acf1aa..f3aac3efd51c 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c | |||
| @@ -3795,10 +3795,13 @@ static int ahash_final_no_ctx(struct ahash_request *req) | |||
| 3795 | if (!edesc) | 3795 | if (!edesc) |
| 3796 | return ret; | 3796 | return ret; |
| 3797 | 3797 | ||
| 3798 | state->buf_dma = dma_map_single(ctx->dev, buf, buflen, DMA_TO_DEVICE); | 3798 | if (buflen) { |
| 3799 | if (dma_mapping_error(ctx->dev, state->buf_dma)) { | 3799 | state->buf_dma = dma_map_single(ctx->dev, buf, buflen, |
| 3800 | dev_err(ctx->dev, "unable to map src\n"); | 3800 | DMA_TO_DEVICE); |
| 3801 | goto unmap; | 3801 | if (dma_mapping_error(ctx->dev, state->buf_dma)) { |
| 3802 | dev_err(ctx->dev, "unable to map src\n"); | ||
| 3803 | goto unmap; | ||
| 3804 | } | ||
| 3802 | } | 3805 | } |
| 3803 | 3806 | ||
| 3804 | edesc->dst_dma = dma_map_single(ctx->dev, req->result, digestsize, | 3807 | edesc->dst_dma = dma_map_single(ctx->dev, req->result, digestsize, |
| @@ -3811,9 +3814,17 @@ static int ahash_final_no_ctx(struct ahash_request *req) | |||
| 3811 | 3814 | ||
| 3812 | memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt)); | 3815 | memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt)); |
| 3813 | dpaa2_fl_set_final(in_fle, true); | 3816 | dpaa2_fl_set_final(in_fle, true); |
| 3814 | dpaa2_fl_set_format(in_fle, dpaa2_fl_single); | 3817 | /* |
| 3815 | dpaa2_fl_set_addr(in_fle, state->buf_dma); | 3818 | * crypto engine requires the input entry to be present when |
| 3816 | dpaa2_fl_set_len(in_fle, buflen); | 3819 | * "frame list" FD is used. |
| 3820 | * Since engine does not support FMT=2'b11 (unused entry type), leaving | ||
| 3821 | * in_fle zeroized (except for "Final" flag) is the best option. | ||
| 3822 | */ | ||
| 3823 | if (buflen) { | ||
| 3824 | dpaa2_fl_set_format(in_fle, dpaa2_fl_single); | ||
| 3825 | dpaa2_fl_set_addr(in_fle, state->buf_dma); | ||
| 3826 | dpaa2_fl_set_len(in_fle, buflen); | ||
| 3827 | } | ||
| 3817 | dpaa2_fl_set_format(out_fle, dpaa2_fl_single); | 3828 | dpaa2_fl_set_format(out_fle, dpaa2_fl_single); |
| 3818 | dpaa2_fl_set_addr(out_fle, edesc->dst_dma); | 3829 | dpaa2_fl_set_addr(out_fle, edesc->dst_dma); |
| 3819 | dpaa2_fl_set_len(out_fle, digestsize); | 3830 | dpaa2_fl_set_len(out_fle, digestsize); |
