From 94002c07ff0e207a883519ccc35c0b5390b29331 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sat, 15 May 2010 23:21:43 +0200 Subject: 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/) // @@ 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); // Signed-off-by: Julia Lawall Signed-off-by: Greg Kroah-Hartman --- drivers/staging/pohmelfs/config.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'drivers/staging/pohmelfs') diff --git a/drivers/staging/pohmelfs/config.c b/drivers/staging/pohmelfs/config.c index 9fdf2de347ea..8c8d1c282e7e 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) } if (g->hash_keysize) { - psb->hash_key = kmalloc(g->hash_keysize, GFP_KERNEL); + psb->hash_key = kmemdup(g->hash_key, g->hash_keysize, + GFP_KERNEL); if (!psb->hash_key) goto err_out_free_cipher_string; - memcpy(psb->hash_key, g->hash_key, g->hash_keysize); psb->hash_keysize = g->hash_keysize; } if (g->cipher_keysize) { - psb->cipher_key = kmalloc(g->cipher_keysize, GFP_KERNEL); + psb->cipher_key = kmemdup(g->cipher_key, g->cipher_keysize, + GFP_KERNEL); if (!psb->cipher_key) goto err_out_free_hash; - memcpy(psb->cipher_key, g->cipher_key, g->cipher_keysize); psb->cipher_keysize = g->cipher_keysize; } @@ -454,14 +454,12 @@ static int pohmelfs_crypto_hash_init(struct pohmelfs_config_group *g, struct poh g->hash_strlen = c->strlen; g->hash_keysize = c->keysize; - g->hash_key = kmalloc(c->keysize, GFP_KERNEL); + g->hash_key = kmemdup(key, c->keysize, GFP_KERNEL); if (!g->hash_key) { kfree(g->hash_string); return -ENOMEM; } - memcpy(g->hash_key, key, c->keysize); - return 0; } @@ -479,14 +477,12 @@ static int pohmelfs_crypto_cipher_init(struct pohmelfs_config_group *g, struct p g->cipher_strlen = c->strlen; g->cipher_keysize = c->keysize; - g->cipher_key = kmalloc(c->keysize, GFP_KERNEL); + g->cipher_key = kmemdup(key, c->keysize, GFP_KERNEL); if (!g->cipher_key) { kfree(g->cipher_string); return -ENOMEM; } - memcpy(g->cipher_key, key, c->keysize); - return 0; } -- cgit v1.2.3