Commit 9cc6f743 authored by Andrzej Hajda's avatar Andrzej Hajda Committed by Ingo Molnar

x86/microcode: Use kmemdup() rather than duplicating its implementation

The patch was generated using fixed coccinelle semantic patch
scripts/coccinelle/api/memdup.cocci.
Signed-off-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
Signed-off-by: default avatarBorislav 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.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 84aba677
...@@ -788,15 +788,13 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover) ...@@ -788,15 +788,13 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)
return -EINVAL; return -EINVAL;
} }
patch->data = kzalloc(patch_size, GFP_KERNEL); patch->data = kmemdup(fw + SECTION_HDR_SIZE, patch_size, GFP_KERNEL);
if (!patch->data) { if (!patch->data) {
pr_err("Patch data allocation failure.\n"); pr_err("Patch data allocation failure.\n");
kfree(patch); kfree(patch);
return -EINVAL; return -EINVAL;
} }
/* All looks ok, copy patch... */
memcpy(patch->data, fw + SECTION_HDR_SIZE, patch_size);
INIT_LIST_HEAD(&patch->plist); INIT_LIST_HEAD(&patch->plist);
patch->patch_id = mc_hdr->patch_id; patch->patch_id = mc_hdr->patch_id;
patch->equiv_cpu = proc_id; patch->equiv_cpu = proc_id;
......
...@@ -210,13 +210,11 @@ save_microcode(struct mc_saved_data *mcs, ...@@ -210,13 +210,11 @@ save_microcode(struct mc_saved_data *mcs,
mc_hdr = &mc->hdr; mc_hdr = &mc->hdr;
size = get_totalsize(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]) { if (!saved_ptr[i]) {
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
} }
memcpy(saved_ptr[i], mc, size);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment