Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] crypto: Use zeroing memory allocator instead of allocator/memset
@ 2017-12-31 12:24 Himanshu Jha
  2017-12-31 15:46 ` Joe Perches
  2018-01-12 12:23 ` Herbert Xu
  0 siblings, 2 replies; 5+ messages in thread
From: Himanshu Jha @ 2017-12-31 12:24 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-crypto, linux-kernel, Himanshu Jha

Use dma_zalloc_coherent for allocating zeroed
memory and remove unnecessary memset function.

Done using Coccinelle.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
0-day tested with no failures.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
---
 drivers/crypto/amcc/crypto4xx_core.c | 8 +++-----
 drivers/crypto/ixp4xx_crypto.c       | 7 +++----
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index c44954e..2cfc69d 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -275,14 +275,12 @@ static u32 crypto4xx_put_pd_to_pdr(struct crypto4xx_device *dev, u32 idx)
  */
 static u32 crypto4xx_build_gdr(struct crypto4xx_device *dev)
 {
-	dev->gdr = dma_alloc_coherent(dev->core_dev->device,
-				      sizeof(struct ce_gd) * PPC4XX_NUM_GD,
-				      &dev->gdr_pa, GFP_ATOMIC);
+	dev->gdr = dma_zalloc_coherent(dev->core_dev->device,
+				       sizeof(struct ce_gd) * PPC4XX_NUM_GD,
+				       &dev->gdr_pa, GFP_ATOMIC);
 	if (!dev->gdr)
 		return -ENOMEM;
 
-	memset(dev->gdr, 0, sizeof(struct ce_gd) * PPC4XX_NUM_GD);
-
 	return 0;
 }
 
diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 8705b28..717a266 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -260,12 +260,11 @@ static int setup_crypt_desc(void)
 {
 	struct device *dev = &pdev->dev;
 	BUILD_BUG_ON(sizeof(struct crypt_ctl) != 64);
-	crypt_virt = dma_alloc_coherent(dev,
-			NPE_QLEN * sizeof(struct crypt_ctl),
-			&crypt_phys, GFP_ATOMIC);
+	crypt_virt = dma_zalloc_coherent(dev,
+					 NPE_QLEN * sizeof(struct crypt_ctl),
+					 &crypt_phys, GFP_ATOMIC);
 	if (!crypt_virt)
 		return -ENOMEM;
-	memset(crypt_virt, 0, NPE_QLEN * sizeof(struct crypt_ctl));
 	return 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: Use zeroing memory allocator instead of allocator/memset
  2017-12-31 12:24 [PATCH] crypto: Use zeroing memory allocator instead of allocator/memset Himanshu Jha
@ 2017-12-31 15:46 ` Joe Perches
  2017-12-31 16:46   ` Himanshu Jha
  2018-01-12 12:23 ` Herbert Xu
  1 sibling, 1 reply; 5+ messages in thread
From: Joe Perches @ 2017-12-31 15:46 UTC (permalink / raw)
  To: Himanshu Jha, herbert, davem; +Cc: linux-crypto, linux-kernel

On Sun, 2017-12-31 at 17:54 +0530, Himanshu Jha wrote:
> Use dma_zalloc_coherent for allocating zeroed
> memory and remove unnecessary memset function.
> 
> Done using Coccinelle.
> Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

I thought you were going to change this tag to
not use the "-by:" form and use something else
like "generated-using:" or "created-with:".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: Use zeroing memory allocator instead of allocator/memset
  2017-12-31 15:46 ` Joe Perches
@ 2017-12-31 16:46   ` Himanshu Jha
  2017-12-31 17:10     ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Himanshu Jha @ 2017-12-31 16:46 UTC (permalink / raw)
  To: Joe Perches; +Cc: herbert, davem, linux-crypto, linux-kernel, julia.lawall

On Sun, Dec 31, 2017 at 07:46:09AM -0800, Joe Perches wrote:
> On Sun, 2017-12-31 at 17:54 +0530, Himanshu Jha wrote:
> > Use dma_zalloc_coherent for allocating zeroed
> > memory and remove unnecessary memset function.
> > 
> > Done using Coccinelle.
> > Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> 
> I thought you were going to change this tag to
> not use the "-by:" form and use something else
> like "generated-using:" or "created-with:".

Thanks for pointing that out!

I was going to ask this to Julia for the appropriate tag, but it slipped
my mind. In future I will definitely choose more appropriate tag
on the Coccinelle patches.

Just to give an insight of the problem to everyone :

While running checkpatch on patches involving the above Generated-by
tag, which is generally used to specify the cocci script used,
checkpatch prompts the below warning and error :

WARNING: Non-standard signature: Generated-by:
#10:
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

ERROR: Unrecognized email address:
'scripts/coccinelle/api/alloc/kzalloc-simple.cocci'

Joe suggested to not use the "-by:" form since it should be reserved
for actual people's names and email addresses.
And if you use other tag than the "-by:" tag, then there is no
error/warning produced.

Thanks
Himanshu Jha

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: Use zeroing memory allocator instead of allocator/memset
  2017-12-31 16:46   ` Himanshu Jha
@ 2017-12-31 17:10     ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2017-12-31 17:10 UTC (permalink / raw)
  To: Himanshu Jha; +Cc: Joe Perches, herbert, davem, linux-crypto, linux-kernel



On Sun, 31 Dec 2017, Himanshu Jha wrote:

> On Sun, Dec 31, 2017 at 07:46:09AM -0800, Joe Perches wrote:
> > On Sun, 2017-12-31 at 17:54 +0530, Himanshu Jha wrote:
> > > Use dma_zalloc_coherent for allocating zeroed
> > > memory and remove unnecessary memset function.
> > >
> > > Done using Coccinelle.
> > > Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> >
> > I thought you were going to change this tag to
> > not use the "-by:" form and use something else
> > like "generated-using:" or "created-with:".
>
> Thanks for pointing that out!
>
> I was going to ask this to Julia for the appropriate tag, but it slipped
> my mind. In future I will definitely choose more appropriate tag
> on the Coccinelle patches.
>
> Just to give an insight of the problem to everyone :
>
> While running checkpatch on patches involving the above Generated-by
> tag, which is generally used to specify the cocci script used,
> checkpatch prompts the below warning and error :
>
> WARNING: Non-standard signature: Generated-by:
> #10:
> Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
> ERROR: Unrecognized email address:
> 'scripts/coccinelle/api/alloc/kzalloc-simple.cocci'
>
> Joe suggested to not use the "-by:" form since it should be reserved
> for actual people's names and email addresses.
> And if you use other tag than the "-by:" tag, then there is no
> error/warning produced.

kbuild uses eg

Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci

julia


>
> Thanks
> Himanshu Jha
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: Use zeroing memory allocator instead of allocator/memset
  2017-12-31 12:24 [PATCH] crypto: Use zeroing memory allocator instead of allocator/memset Himanshu Jha
  2017-12-31 15:46 ` Joe Perches
@ 2018-01-12 12:23 ` Herbert Xu
  1 sibling, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2018-01-12 12:23 UTC (permalink / raw)
  To: Himanshu Jha; +Cc: davem, linux-crypto, linux-kernel

On Sun, Dec 31, 2017 at 05:54:23PM +0530, Himanshu Jha wrote:
> Use dma_zalloc_coherent for allocating zeroed
> memory and remove unnecessary memset function.
> 
> Done using Coccinelle.
> Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> 0-day tested with no failures.
> 
> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-12 12:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-31 12:24 [PATCH] crypto: Use zeroing memory allocator instead of allocator/memset Himanshu Jha
2017-12-31 15:46 ` Joe Perches
2017-12-31 16:46   ` Himanshu Jha
2017-12-31 17:10     ` Julia Lawall
2018-01-12 12:23 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox