Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 915e4e8413da ("crypto: hisilicon - SEC security accelerator driver")
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Yunfeng Ye and committed by
Herbert Xu
e00371af 24fbf7ba

+19 -25
+19 -25
drivers/crypto/hisilicon/sec/sec_algs.c
··· 153 153 ctx->cipher_alg); 154 154 } 155 155 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 + 156 174 static int sec_alloc_and_fill_hw_sgl(struct sec_hw_sgl **sec_sgl, 157 175 dma_addr_t *psec_sgl, 158 176 struct scatterlist *sgl, ··· 217 199 return 0; 218 200 219 201 err_free_hw_sgls: 220 - sgl_current = *sec_sgl; 221 - while (sgl_current) { 222 - sgl_next = sgl_current->next; 223 - dma_pool_free(info->hw_sgl_pool, sgl_current, 224 - sgl_current->next_sgl); 225 - sgl_current = sgl_next; 226 - } 202 + sec_free_hw_sgl(*sec_sgl, *psec_sgl, info); 227 203 *psec_sgl = 0; 228 204 229 205 return ret; 230 - } 231 - 232 - static void sec_free_hw_sgl(struct sec_hw_sgl *hw_sgl, 233 - dma_addr_t psec_sgl, struct sec_dev_info *info) 234 - { 235 - struct sec_hw_sgl *sgl_current, *sgl_next; 236 - dma_addr_t sgl_next_dma; 237 - 238 - sgl_current = hw_sgl; 239 - while (sgl_current) { 240 - sgl_next = sgl_current->next; 241 - sgl_next_dma = sgl_current->next_sgl; 242 - 243 - dma_pool_free(info->hw_sgl_pool, sgl_current, psec_sgl); 244 - 245 - sgl_current = sgl_next; 246 - psec_sgl = sgl_next_dma; 247 - } 248 206 } 249 207 250 208 static int sec_alg_skcipher_setkey(struct crypto_skcipher *tfm,