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

Configure Feed

Select the types of activity you want to include in your feed.

crypto: sun8i-ss - Remove GFP_DMA and add DMA alignment padding

GFP_DMA does not guarantee that the returned memory is aligned
for DMA. In fact for sun8i-ss it is superfluous and can be removed.

However, kmalloc may start returning DMA-unaligned memory in future
so fix this by adding the alignment by hand.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Tested-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Acked-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+21 -11
+2 -2
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
··· 452 452 } 453 453 kfree_sensitive(op->key); 454 454 op->keylen = keylen; 455 - op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); 455 + op->key = kmemdup(key, keylen, GFP_KERNEL); 456 456 if (!op->key) 457 457 return -ENOMEM; 458 458 ··· 475 475 476 476 kfree_sensitive(op->key); 477 477 op->keylen = keylen; 478 - op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); 478 + op->key = kmemdup(key, keylen, GFP_KERNEL); 479 479 if (!op->key) 480 480 return -ENOMEM; 481 481
+8 -5
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/io.h> 18 18 #include <linux/irq.h> 19 + #include <linux/kernel.h> 19 20 #include <linux/module.h> 20 21 #include <linux/of.h> 21 22 #include <linux/of_device.h> ··· 528 527 init_completion(&ss->flows[i].complete); 529 528 530 529 ss->flows[i].biv = devm_kmalloc(ss->dev, AES_BLOCK_SIZE, 531 - GFP_KERNEL | GFP_DMA); 530 + GFP_KERNEL); 532 531 if (!ss->flows[i].biv) { 533 532 err = -ENOMEM; 534 533 goto error_engine; ··· 536 535 537 536 for (j = 0; j < MAX_SG; j++) { 538 537 ss->flows[i].iv[j] = devm_kmalloc(ss->dev, AES_BLOCK_SIZE, 539 - GFP_KERNEL | GFP_DMA); 538 + GFP_KERNEL); 540 539 if (!ss->flows[i].iv[j]) { 541 540 err = -ENOMEM; 542 541 goto error_engine; ··· 545 544 546 545 /* the padding could be up to two block. */ 547 546 ss->flows[i].pad = devm_kmalloc(ss->dev, MAX_PAD_SIZE, 548 - GFP_KERNEL | GFP_DMA); 547 + GFP_KERNEL); 549 548 if (!ss->flows[i].pad) { 550 549 err = -ENOMEM; 551 550 goto error_engine; 552 551 } 553 - ss->flows[i].result = devm_kmalloc(ss->dev, SHA256_DIGEST_SIZE, 554 - GFP_KERNEL | GFP_DMA); 552 + ss->flows[i].result = 553 + devm_kmalloc(ss->dev, max(SHA256_DIGEST_SIZE, 554 + dma_get_cache_alignment()), 555 + GFP_KERNEL); 555 556 if (!ss->flows[i].result) { 556 557 err = -ENOMEM; 557 558 goto error_engine;
+2 -2
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
··· 79 79 memcpy(tfmctx->key, key, keylen); 80 80 } 81 81 82 - tfmctx->ipad = kzalloc(bs, GFP_KERNEL | GFP_DMA); 82 + tfmctx->ipad = kzalloc(bs, GFP_KERNEL); 83 83 if (!tfmctx->ipad) 84 84 return -ENOMEM; 85 - tfmctx->opad = kzalloc(bs, GFP_KERNEL | GFP_DMA); 85 + tfmctx->opad = kzalloc(bs, GFP_KERNEL); 86 86 if (!tfmctx->opad) { 87 87 ret = -ENOMEM; 88 88 goto err_opad;
+9 -2
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
··· 11 11 */ 12 12 #include "sun8i-ss.h" 13 13 #include <linux/dma-mapping.h> 14 + #include <linux/kernel.h> 15 + #include <linux/mm.h> 14 16 #include <linux/pm_runtime.h> 15 17 #include <crypto/internal/rng.h> 16 18 ··· 27 25 ctx->seed = NULL; 28 26 } 29 27 if (!ctx->seed) 30 - ctx->seed = kmalloc(slen, GFP_KERNEL | GFP_DMA); 28 + ctx->seed = kmalloc(slen, GFP_KERNEL); 31 29 if (!ctx->seed) 32 30 return -ENOMEM; 33 31 ··· 60 58 struct sun8i_ss_rng_tfm_ctx *ctx = crypto_rng_ctx(tfm); 61 59 struct rng_alg *alg = crypto_rng_alg(tfm); 62 60 struct sun8i_ss_alg_template *algt; 61 + unsigned int todo_with_padding; 63 62 struct sun8i_ss_dev *ss; 64 63 dma_addr_t dma_iv, dma_dst; 65 64 unsigned int todo; ··· 84 81 todo = dlen + PRNG_SEED_SIZE + PRNG_DATA_SIZE; 85 82 todo -= todo % PRNG_DATA_SIZE; 86 83 87 - d = kzalloc(todo, GFP_KERNEL | GFP_DMA); 84 + todo_with_padding = ALIGN(todo, dma_get_cache_alignment()); 85 + if (todo_with_padding < todo || todo < dlen) 86 + return -EOVERFLOW; 87 + 88 + d = kzalloc(todo_with_padding, GFP_KERNEL); 88 89 if (!d) 89 90 return -ENOMEM; 90 91