From: Borislav Petkov <bp@amd64.org>
To: <x86@kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
Borislav Petkov <borislav.petkov@amd.com>
Subject: [PATCH 4/7] x86, microcode, AMD: Simplify install_equiv_cpu_table
Date: Mon, 24 Jan 2011 16:29:00 +0100 [thread overview]
Message-ID: <1295882943-11184-5-git-send-email-bp@amd64.org> (raw)
In-Reply-To: <1295882943-11184-1-git-send-email-bp@amd64.org>
From: Borislav Petkov <borislav.petkov@amd.com>
There's no need to memcpy the ucode header in order to look at it only
in this function - use the original buffer instead. Also, fix return
type semantics by returning a negative value on error and a positive
otherwise.
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
Acked-by: Andreas Herrmann <Andreas.Herrmann3@amd.com>
---
arch/x86/kernel/microcode_amd.c | 21 ++++++++-------------
1 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index ef91df0..9a451d7 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -188,27 +188,22 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
static int install_equiv_cpu_table(const u8 *buf)
{
- u8 *container_hdr[UCODE_CONTAINER_HEADER_SIZE];
- unsigned int *buf_pos = (unsigned int *)container_hdr;
- unsigned long size;
+ unsigned int *ibuf = (unsigned int *)buf;
+ unsigned int type = ibuf[1];
+ unsigned int size = ibuf[2];
- get_ucode_data(&container_hdr, buf, UCODE_CONTAINER_HEADER_SIZE);
-
- size = buf_pos[2];
-
- if (buf_pos[1] != UCODE_EQUIV_CPU_TABLE_TYPE || !size) {
+ if (type != UCODE_EQUIV_CPU_TABLE_TYPE || !size) {
pr_err("error: invalid type field in container file section header\n");
- return 0;
+ return -EINVAL;
}
equiv_cpu_table = vmalloc(size);
if (!equiv_cpu_table) {
pr_err("failed to allocate equivalent CPU table\n");
- return 0;
+ return -ENOMEM;
}
- buf += UCODE_CONTAINER_HEADER_SIZE;
- get_ucode_data(equiv_cpu_table, buf, size);
+ get_ucode_data(equiv_cpu_table, buf + UCODE_CONTAINER_HEADER_SIZE, size);
return size + UCODE_CONTAINER_HEADER_SIZE; /* add header length */
}
@@ -232,7 +227,7 @@ generic_load_microcode(int cpu, const u8 *data, size_t size)
enum ucode_state state = UCODE_OK;
offset = install_equiv_cpu_table(ucode_ptr);
- if (!offset) {
+ if (offset < 0) {
pr_err("failed to create equivalent cpu table\n");
return UCODE_ERROR;
}
--
1.7.4.rc2
next prev parent reply other threads:[~2011-01-24 15:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-24 15:28 [PATCH 0/7] x86, microcode, AMD: Some fixes Borislav Petkov
2011-01-24 15:28 ` [PATCH 1/7] sysdev: Do not register with sysdev when erroring on add Borislav Petkov
2011-01-26 12:00 ` Borislav Petkov
2011-01-31 22:16 ` Greg KH
2011-01-31 22:33 ` Borislav Petkov
2011-01-31 22:50 ` Greg KH
2011-01-24 15:28 ` [PATCH 2/7] x86, microcode: Correct sysdev_add error path Borislav Petkov
2011-01-24 15:28 ` [PATCH 3/7] x86, microcode, AMD: Release firmware on error Borislav Petkov
2011-01-24 15:29 ` Borislav Petkov [this message]
2011-01-24 15:29 ` [PATCH 5/7] x86, microcode, AMD: Simplify get_next_ucode Borislav Petkov
2011-01-24 15:29 ` [PATCH 6/7] x86, microcode, AMD: Remove unneeded memset call Borislav Petkov
2011-01-24 15:29 ` [PATCH 7/7] x86, microcode, AMD: Cleanup dmesg output Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1295882943-11184-5-git-send-email-bp@amd64.org \
--to=bp@amd64.org \
--cc=borislav.petkov@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox