crypto: qat - unmap buffer before free for DH
authorHareshx Sankar Raj <hareshx.sankar.raj@intel.com>
Mon, 5 Jun 2023 21:06:06 +0000 (22:06 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Jul 2023 14:21:42 +0000 (16:21 +0200)
[ Upstream commit eb7713f5ca97697b92f225127440d1525119b8de ]

The callback function for DH frees the memory allocated for the
destination buffer before unmapping it.
This sequence is wrong.

Change the cleanup sequence to unmap the buffer before freeing it.

Fixes: 029aa4624a7f ("crypto: qat - remove dma_free_coherent() for DH")
Signed-off-by: Hareshx Sankar Raj <hareshx.sankar.raj@intel.com>
Co-developed-by: Bolemx Sivanagaleela <bolemx.sivanagaleela@intel.com>
Signed-off-by: Bolemx Sivanagaleela <bolemx.sivanagaleela@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/qat/qat_common/qat_asym_algs.c

index 935a7e012946e30b3b703e7d427449909b53ec1e..8806242469a0648f2671e78d4880fb722602400d 100644 (file)
@@ -170,15 +170,14 @@ static void qat_dh_cb(struct icp_qat_fw_pke_resp *resp)
        }
 
        areq->dst_len = req->ctx.dh->p_size;
+       dma_unmap_single(dev, req->out.dh.r, req->ctx.dh->p_size,
+                        DMA_FROM_DEVICE);
        if (req->dst_align) {
                scatterwalk_map_and_copy(req->dst_align, areq->dst, 0,
                                         areq->dst_len, 1);
                kfree_sensitive(req->dst_align);
        }
 
-       dma_unmap_single(dev, req->out.dh.r, req->ctx.dh->p_size,
-                        DMA_FROM_DEVICE);
-
        dma_unmap_single(dev, req->phy_in, sizeof(struct qat_dh_input_params),
                         DMA_TO_DEVICE);
        dma_unmap_single(dev, req->phy_out,