Skip to content

Commit e00371a

Browse files
yeyunfeng-devherbertx
authored andcommitted
crypto: hisilicon - Matching the dma address for dma_pool_free()
When dma_pool_zalloc() fail in sec_alloc_and_fill_hw_sgl(), dma_pool_free() is invoked, but the parameters that sgl_current and sgl_current->next_sgl is not match. Using sec_free_hw_sgl() instead of the original free routine. Fixes: 915e4e8 ("crypto: hisilicon - SEC security accelerator driver") Signed-off-by: Yunfeng Ye <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 24fbf7b commit e00371a

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

drivers/crypto/hisilicon/sec/sec_algs.c

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,24 @@ static void sec_alg_skcipher_init_context(struct crypto_skcipher *atfm,
153153
ctx->cipher_alg);
154154
}
155155

156+
static void sec_free_hw_sgl(struct sec_hw_sgl *hw_sgl,
157+
dma_addr_t psec_sgl, struct sec_dev_info *info)
158+
{
159+
struct sec_hw_sgl *sgl_current, *sgl_next;
160+
dma_addr_t sgl_next_dma;
161+
162+
sgl_current = hw_sgl;
163+
while (sgl_current) {
164+
sgl_next = sgl_current->next;
165+
sgl_next_dma = sgl_current->next_sgl;
166+
167+
dma_pool_free(info->hw_sgl_pool, sgl_current, psec_sgl);
168+
169+
sgl_current = sgl_next;
170+
psec_sgl = sgl_next_dma;
171+
}
172+
}
173+
156174
static int sec_alloc_and_fill_hw_sgl(struct sec_hw_sgl **sec_sgl,
157175
dma_addr_t *psec_sgl,
158176
struct scatterlist *sgl,
@@ -199,36 +217,12 @@ static int sec_alloc_and_fill_hw_sgl(struct sec_hw_sgl **sec_sgl,
199217
return 0;
200218

201219
err_free_hw_sgls:
202-
sgl_current = *sec_sgl;
203-
while (sgl_current) {
204-
sgl_next = sgl_current->next;
205-
dma_pool_free(info->hw_sgl_pool, sgl_current,
206-
sgl_current->next_sgl);
207-
sgl_current = sgl_next;
208-
}
220+
sec_free_hw_sgl(*sec_sgl, *psec_sgl, info);
209221
*psec_sgl = 0;
210222

211223
return ret;
212224
}
213225

214-
static void sec_free_hw_sgl(struct sec_hw_sgl *hw_sgl,
215-
dma_addr_t psec_sgl, struct sec_dev_info *info)
216-
{
217-
struct sec_hw_sgl *sgl_current, *sgl_next;
218-
dma_addr_t sgl_next_dma;
219-
220-
sgl_current = hw_sgl;
221-
while (sgl_current) {
222-
sgl_next = sgl_current->next;
223-
sgl_next_dma = sgl_current->next_sgl;
224-
225-
dma_pool_free(info->hw_sgl_pool, sgl_current, psec_sgl);
226-
227-
sgl_current = sgl_next;
228-
psec_sgl = sgl_next_dma;
229-
}
230-
}
231-
232226
static int sec_alg_skcipher_setkey(struct crypto_skcipher *tfm,
233227
const u8 *key, unsigned int keylen,
234228
enum sec_cipher_alg alg)

0 commit comments

Comments
 (0)