[PATCH] lib/digsig: Remove unnecessary memset

Liao Yuanhong posted 1 patch 1 month, 3 weeks ago
lib/digsig.c | 1 -
1 file changed, 1 deletion(-)
[PATCH] lib/digsig: Remove unnecessary memset
Posted by Liao Yuanhong 1 month, 3 weeks ago
kzalloc() has already been initialized to full 0 space, there is no need to
use memset() to initialize again.

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
 lib/digsig.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lib/digsig.c b/lib/digsig.c
index 04b5e55ed95f..2b36f9cc91e9 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -159,7 +159,6 @@ static int digsig_verify_rsa(struct key *key,
 
 	len = mlen;
 	head = len - l;
-	memset(out1, 0, head);
 	memcpy(out1 + head, p, l);
 
 	kfree(p);
-- 
2.34.1
Re: [PATCH] lib/digsig: Remove unnecessary memset
Posted by Andrew Morton 1 month, 3 weeks ago
On Mon, 11 Aug 2025 16:27:38 +0800 Liao Yuanhong <liaoyuanhong@vivo.com> wrote:

> kzalloc() has already been initialized to full 0 space, there is no need to
> use memset() to initialize again.
> 
> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
> ---
>  lib/digsig.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/lib/digsig.c b/lib/digsig.c
> index 04b5e55ed95f..2b36f9cc91e9 100644
> --- a/lib/digsig.c
> +++ b/lib/digsig.c
> @@ -159,7 +159,6 @@ static int digsig_verify_rsa(struct key *key,
>  
>  	len = mlen;
>  	head = len - l;
> -	memset(out1, 0, head);
>  	memcpy(out1 + head, p, l);
>  
>  	kfree(p);

It would be a little faster to leave this part as-is and replace the
kzalloc() with kmalloc(), no?  Seems that `mlen' will be small, so any
difference will be unmeasurable..