x86/microcode: Use kmemdup() rather than duplicating its implementation
authorAndrzej Hajda <a.hajda@samsung.com>
Tue, 16 Feb 2016 08:43:20 +0000 (09:43 +0100)
committerIngo Molnar <mingo@kernel.org>
Wed, 17 Feb 2016 07:46:08 +0000 (08:46 +0100)
The patch was generated using fixed coccinelle semantic patch
scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1455612202-14414-3-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/cpu/microcode/amd.c
arch/x86/kernel/cpu/microcode/intel.c

index f66cbfe74ce4cb32476a8cb52df5e05a5766cda3..e397fc160b05470f48bf8d693988f4c06b2799ec 100644 (file)
@@ -788,15 +788,13 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)
                return -EINVAL;
        }
 
-       patch->data = kzalloc(patch_size, GFP_KERNEL);
+       patch->data = kmemdup(fw + SECTION_HDR_SIZE, patch_size, GFP_KERNEL);
        if (!patch->data) {
                pr_err("Patch data allocation failure.\n");
                kfree(patch);
                return -EINVAL;
        }
 
-       /* All looks ok, copy patch... */
-       memcpy(patch->data, fw + SECTION_HDR_SIZE, patch_size);
        INIT_LIST_HEAD(&patch->plist);
        patch->patch_id  = mc_hdr->patch_id;
        patch->equiv_cpu = proc_id;
index cb397947f688692ac0e1cbaf589cd757230bc5e8..cbb3cf09b0652a7556649237598c9f74e53744c7 100644 (file)
@@ -210,13 +210,11 @@ save_microcode(struct mc_saved_data *mcs,
                mc_hdr = &mc->hdr;
                size   = get_totalsize(mc_hdr);
 
-               saved_ptr[i] = kmalloc(size, GFP_KERNEL);
+               saved_ptr[i] = kmemdup(mc, size, GFP_KERNEL);
                if (!saved_ptr[i]) {
                        ret = -ENOMEM;
                        goto err;
                }
-
-               memcpy(saved_ptr[i], mc, size);
        }
 
        /*