[S390] drivers/s390/char: Use kmemdup
authorJulia Lawall <julia@diku.dk>
Mon, 17 May 2010 08:00:23 +0000 (10:00 +0200)
committerMartin Schwidefsky <sky@mschwide.boeblingen.de.ibm.com>
Mon, 17 May 2010 08:00:18 +0000 (10:00 +0200)
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: Martin Schwidefsky <schwidefsky@de.ibm.com>
drivers/s390/char/keyboard.c

index 24021fd7de2547161506d1733d9014f6cbcf3c30..18d9a497863bd5c2cdc3b4ba2160bdd450a19e4e 100644 (file)
@@ -59,12 +59,11 @@ kbd_alloc(void) {
                goto out_kbd;
        for (i = 0; i < ARRAY_SIZE(key_maps); i++) {
                if (key_maps[i]) {
-                       kbd->key_maps[i] =
-                               kmalloc(sizeof(u_short)*NR_KEYS, GFP_KERNEL);
+                       kbd->key_maps[i] = kmemdup(key_maps[i],
+                                                  sizeof(u_short) * NR_KEYS,
+                                                  GFP_KERNEL);
                        if (!kbd->key_maps[i])
                                goto out_maps;
-                       memcpy(kbd->key_maps[i], key_maps[i],
-                              sizeof(u_short)*NR_KEYS);
                }
        }
        kbd->func_table = kzalloc(sizeof(func_table), GFP_KERNEL);
@@ -82,12 +81,11 @@ kbd_alloc(void) {
                kzalloc(sizeof(fn_handler_fn *) * NR_FN_HANDLER, GFP_KERNEL);
        if (!kbd->fn_handler)
                goto out_func;
-       kbd->accent_table =
-               kmalloc(sizeof(struct kbdiacruc)*MAX_DIACR, GFP_KERNEL);
+       kbd->accent_table = kmemdup(accent_table,
+                                   sizeof(struct kbdiacruc) * MAX_DIACR,
+                                   GFP_KERNEL);
        if (!kbd->accent_table)
                goto out_fn_handler;
-       memcpy(kbd->accent_table, accent_table,
-              sizeof(struct kbdiacruc)*MAX_DIACR);
        kbd->accent_table_size = accent_table_size;
        return kbd;