Skip to contentSkip to conversation

tools/testing/crypto: Use vzalloc instead of vmalloc+memset

PATCH In review Siddh Raman Pant 3 participants 4 messages Jun 27, 2022 – Jun 28, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/testing/crypto: Use vzalloc instead of vmalloc+memset

This fixes the corresponding coccinelle warning.

---
 tools/testing/crypto/chacha20-s390/test-cipher.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/testing/crypto/chacha20-s390/test-cipher.c +3 -6
index 34e8b855266f..8141d45df51a 100644
@@ -252,29 +252,26 @@ static int __init chacha_s390_test_init(void)
 	memset(plain, 'a', data_size);
 	get_random_bytes(plain, (data_size > 256 ? 256 : data_size));
 
-	cipher_generic = vmalloc(data_size);
+	cipher_generic = vzalloc(data_size);
 	if (!cipher_generic) {
 		pr_info("could not allocate cipher_generic buffer\n");
 		ret = -2;
 		goto out;
 	}
-	memset(cipher_generic, 0, data_size);
 
-	cipher_s390 = vmalloc(data_size);
+	cipher_s390 = vzalloc(data_size);
 	if (!cipher_s390) {
 		pr_info("could not allocate cipher_s390 buffer\n");
 		ret = -2;
 		goto out;
 	}
-	memset(cipher_s390, 0, data_size);
 
-	revert = vmalloc(data_size);
+	revert = vzalloc(data_size);
 	if (!revert) {
 		pr_info("could not allocate revert buffer\n");
 		ret = -2;
 		goto out;
 	}
-	memset(revert, 0, data_size);
 
 	if (debug)
 		print_hex_dump(KERN_INFO, "src: ", DUMP_PREFIX_OFFSET,
Signature · 1 line
2.35.1
#1 lore raw
Quoted 35 lines · Siddh Raman Pant

This fixes the corresponding coccinelle warning.

---
 tools/testing/crypto/chacha20-s390/test-cipher.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/testing/crypto/chacha20-s390/test-cipher.c +2 -5
index 34e8b855266f..8141d45df51a 100644
@@ -252,29 +252,26 @@ static int __init chacha_s390_test_init(void)
 	memset(plain, 'a', data_size);
 	get_random_bytes(plain, (data_size > 256 ? 256 : data_size));
 
-	cipher_generic = vmalloc(data_size);
+	cipher_generic = vzalloc(data_size);
 	if (!cipher_generic) {
 		pr_info("could not allocate cipher_generic buffer\n");
 		ret = -2;
 		goto out;
 	}
-	memset(cipher_generic, 0, data_size);
 
-	cipher_s390 = vmalloc(data_size);
+	cipher_s390 = vzalloc(data_size);
 	if (!cipher_s390) {
 		pr_info("could not allocate cipher_s390 buffer\n");
 		ret = -2;
 		goto out;
 	}
-	memset(cipher_s390, 0, data_size);
 
-	revert = vmalloc(data_size);

tools/testing/crypto/chacha20-s390/test-cipher.c static int __init chacha_s390_test_init(void) · line 277

Quoted 10 lines
tools/testing/crypto/chacha20-s390/test-cipher.c +1 -1
+	revert = vzalloc(data_size);
 	if (!revert) {
 		pr_info("could not allocate revert buffer\n");
 		ret = -2;
 		goto out;
 	}
-	memset(revert, 0, data_size);
 
 	if (debug)
 		print_hex_dump(KERN_INFO, "src: ", DUMP_PREFIX_OFFSET,

Thanks Siddh
I'll forward this patch into the s390 subsystem and on the next merge window for the 5.20 kernel then it will appear in the upstream kernel.

#2 lore raw

Thanks, Siddh,

This change makes perfect sense.

Thanks, Harald, for helping with this!

Best regards,
Vladis Dronov | Red Hat, Inc. | The Core Kernel | Senior Software Engineer

Quoted 51 lines · Harald Freudenberger
Quoted 35 lines · Siddh Raman Pant

This fixes the corresponding coccinelle warning.

---
 tools/testing/crypto/chacha20-s390/test-cipher.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/testing/crypto/chacha20-s390/test-cipher.c +2 -5
index 34e8b855266f..8141d45df51a 100644
@@ -252,29 +252,26 @@ static int __init chacha_s390_test_init(void)
      memset(plain, 'a', data_size);
      get_random_bytes(plain, (data_size > 256 ? 256 : data_size));
 
-     cipher_generic = vmalloc(data_size);
+     cipher_generic = vzalloc(data_size);
      if (!cipher_generic) {
              pr_info("could not allocate cipher_generic buffer\n");
              ret = -2;
              goto out;
      }
-     memset(cipher_generic, 0, data_size);
 
-     cipher_s390 = vmalloc(data_size);
+     cipher_s390 = vzalloc(data_size);
      if (!cipher_s390) {
              pr_info("could not allocate cipher_s390 buffer\n");
              ret = -2;
              goto out;
      }
-     memset(cipher_s390, 0, data_size);
 
-     revert = vmalloc(data_size);

tools/testing/crypto/chacha20-s390/test-cipher.c static int __init chacha_s390_test_init(void) · line 277

Quoted 10 lines
tools/testing/crypto/chacha20-s390/test-cipher.c +1 -1
+     revert = vzalloc(data_size);
      if (!revert) {
              pr_info("could not allocate revert buffer\n");
              ret = -2;
              goto out;
      }
-     memset(revert, 0, data_size);
 
      if (debug)
              print_hex_dump(KERN_INFO, "src: ", DUMP_PREFIX_OFFSET,

Thanks Siddh
I'll forward this patch into the s390 subsystem and on the next merge window for the 5.20 kernel then it will appear in the upstream kernel.

#3 lore raw

On Mon, 27 Jun 2022 16:26:12 +0530 Vlad Dronov <[email protected]> wrote

Quoted 3 lines

Thanks, Siddh,

This change makes perfect sense.

On Mon, 27 Jun 2022 15:24:46 +0530 Harald Freudenberger <[email protected]> wrote

Quoted 3 lines

Thanks Siddh
I'll forward this patch into the s390 subsystem and on the next merge window for the 5.20 kernel then it will appear in the upstream kernel.

Thanks Harald, and Vlad.

Apologies for not CC'ng it to the s390 mailing list. The MAINTAINERS file does not have entry for this file. I will send the patch for it.

Thanks,
Siddh
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees