crypto: testmgr - use kmemdup instead of kmalloc+memcpy
authorEric Biggers <ebiggers@google.com>
Fri, 30 Dec 2016 20:12:00 +0000 (14:12 -0600)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 12 Jan 2017 16:24:37 +0000 (00:24 +0800)
It's recommended to use kmemdup instead of kmalloc followed by memcpy.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/testmgr.c

index 44e888b0b041944b44e8aa5d75619e51d7fe52a2..881176ebd8a8a096e48256f5a251431f4b84a9eb 100644 (file)
@@ -1463,13 +1463,12 @@ static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate,
                int ilen = ctemplate[i].inlen;
                void *input_vec;
 
-               input_vec = kmalloc(ilen, GFP_KERNEL);
+               input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
                if (!input_vec) {
                        ret = -ENOMEM;
                        goto out;
                }
 
-               memcpy(input_vec, ctemplate[i].input, ilen);
                memset(output, 0, dlen);
                init_completion(&result.completion);
                sg_init_one(&src, input_vec, ilen);
@@ -1525,13 +1524,12 @@ static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate,
                int ilen = dtemplate[i].inlen;
                void *input_vec;
 
-               input_vec = kmalloc(ilen, GFP_KERNEL);
+               input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
                if (!input_vec) {
                        ret = -ENOMEM;
                        goto out;
                }
 
-               memcpy(input_vec, dtemplate[i].input, ilen);
                memset(output, 0, dlen);
                init_completion(&result.completion);
                sg_init_one(&src, input_vec, ilen);