Commit f386dc64 authored by Yang Shen's avatar Yang Shen Committed by Herbert Xu

crypto: hisilicon - fix missed error branch

If an error occurs in the process after the SGL is mapped
successfully, it need to unmap the SGL.

Otherwise, memory problems may occur.
Signed-off-by: default avatarYang Shen <shenyang39@huawei.com>
Signed-off-by: default avatarChenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 3401f63e
...@@ -225,7 +225,7 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, ...@@ -225,7 +225,7 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
dma_addr_t curr_sgl_dma = 0; dma_addr_t curr_sgl_dma = 0;
struct acc_hw_sge *curr_hw_sge; struct acc_hw_sge *curr_hw_sge;
struct scatterlist *sg; struct scatterlist *sg;
int sg_n; int sg_n, ret;
if (!dev || !sgl || !pool || !hw_sgl_dma || index >= pool->count) if (!dev || !sgl || !pool || !hw_sgl_dma || index >= pool->count)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -240,14 +240,15 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, ...@@ -240,14 +240,15 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
if (sg_n_mapped > pool->sge_nr) { if (sg_n_mapped > pool->sge_nr) {
dev_err(dev, "the number of entries in input scatterlist is bigger than SGL pool setting.\n"); dev_err(dev, "the number of entries in input scatterlist is bigger than SGL pool setting.\n");
return ERR_PTR(-EINVAL); ret = -EINVAL;
goto err_unmap;
} }
curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma); curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma);
if (IS_ERR(curr_hw_sgl)) { if (IS_ERR(curr_hw_sgl)) {
dev_err(dev, "Get SGL error!\n"); dev_err(dev, "Get SGL error!\n");
dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); ret = -ENOMEM;
return ERR_PTR(-ENOMEM); goto err_unmap;
} }
curr_hw_sgl->entry_length_in_sgl = cpu_to_le16(pool->sge_nr); curr_hw_sgl->entry_length_in_sgl = cpu_to_le16(pool->sge_nr);
curr_hw_sge = curr_hw_sgl->sge_entries; curr_hw_sge = curr_hw_sgl->sge_entries;
...@@ -262,6 +263,11 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, ...@@ -262,6 +263,11 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
*hw_sgl_dma = curr_sgl_dma; *hw_sgl_dma = curr_sgl_dma;
return curr_hw_sgl; return curr_hw_sgl;
err_unmap:
dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);
return ERR_PTR(ret);
} }
EXPORT_SYMBOL_GPL(hisi_acc_sg_buf_map_to_hw_sgl); EXPORT_SYMBOL_GPL(hisi_acc_sg_buf_map_to_hw_sgl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment