aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/pohmelfs/config.c
diff options
context:
space:
mode:
authorJulia Lawall <julia@diku.dk>2010-05-15 17:21:43 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-05-17 19:31:15 -0400
commit94002c07ff0e207a883519ccc35c0b5390b29331 (patch)
treeb730a75ef2ad76d1e3a322e5982b30ca46b6c487 /drivers/staging/pohmelfs/config.c
parent96fe9ee2c2dfe3268961f3873ea6098b9b9f27c2 (diff)
Staging: Use kmemdup
Use kmemdup when some other buffer is immediately copied into the allocated region. A simplified version of the semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ expression from,to,size,flag; statement S; @@ - to = \(kmalloc\|kzalloc\)(size,flag); + to = kmemdup(from,size,flag); if (to==NULL || ...) S - memcpy(to, from, size); // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/pohmelfs/config.c')
-rw-r--r--drivers/staging/pohmelfs/config.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/drivers/staging/pohmelfs/config.c b/drivers/staging/pohmelfs/config.c
index 9fdf2de347e..8c8d1c282e7 100644
--- a/drivers/staging/pohmelfs/config.c
+++ b/drivers/staging/pohmelfs/config.c
@@ -204,18 +204,18 @@ int pohmelfs_copy_crypto(struct pohmelfs_sb *psb)
204 } 204 }
205 205
206 if (g->hash_keysize) { 206 if (g->hash_keysize) {
207 psb->hash_key = kmalloc(g->hash_keysize, GFP_KERNEL); 207 psb->hash_key = kmemdup(g->hash_key, g->hash_keysize,
208 GFP_KERNEL);
208 if (!psb->hash_key) 209 if (!psb->hash_key)
209 goto err_out_free_cipher_string; 210 goto err_out_free_cipher_string;
210 memcpy(psb->hash_key, g->hash_key, g->hash_keysize);
211 psb->hash_keysize = g->hash_keysize; 211 psb->hash_keysize = g->hash_keysize;
212 } 212 }
213 213
214 if (g->cipher_keysize) { 214 if (g->cipher_keysize) {
215 psb->cipher_key = kmalloc(g->cipher_keysize, GFP_KERNEL); 215 psb->cipher_key = kmemdup(g->cipher_key, g->cipher_keysize,
216 GFP_KERNEL);
216 if (!psb->cipher_key) 217 if (!psb->cipher_key)
217 goto err_out_free_hash; 218 goto err_out_free_hash;
218 memcpy(psb->cipher_key, g->cipher_key, g->cipher_keysize);
219 psb->cipher_keysize = g->cipher_keysize; 219 psb->cipher_keysize = g->cipher_keysize;
220 } 220 }
221 221
@@ -454,14 +454,12 @@ static int pohmelfs_crypto_hash_init(struct pohmelfs_config_group *g, struct poh
454 g->hash_strlen = c->strlen; 454 g->hash_strlen = c->strlen;
455 g->hash_keysize = c->keysize; 455 g->hash_keysize = c->keysize;
456 456
457 g->hash_key = kmalloc(c->keysize, GFP_KERNEL); 457 g->hash_key = kmemdup(key, c->keysize, GFP_KERNEL);
458 if (!g->hash_key) { 458 if (!g->hash_key) {
459 kfree(g->hash_string); 459 kfree(g->hash_string);
460 return -ENOMEM; 460 return -ENOMEM;
461 } 461 }
462 462
463 memcpy(g->hash_key, key, c->keysize);
464
465 return 0; 463 return 0;
466} 464}
467 465
@@ -479,14 +477,12 @@ static int pohmelfs_crypto_cipher_init(struct pohmelfs_config_group *g, struct p
479 g->cipher_strlen = c->strlen; 477 g->cipher_strlen = c->strlen;
480 g->cipher_keysize = c->keysize; 478 g->cipher_keysize = c->keysize;
481 479
482 g->cipher_key = kmalloc(c->keysize, GFP_KERNEL); 480 g->cipher_key = kmemdup(key, c->keysize, GFP_KERNEL);
483 if (!g->cipher_key) { 481 if (!g->cipher_key) {
484 kfree(g->cipher_string); 482 kfree(g->cipher_string);
485 return -ENOMEM; 483 return -ENOMEM;
486 } 484 }
487 485
488 memcpy(g->cipher_key, key, c->keysize);
489
490 return 0; 486 return 0;
491} 487}
492 488