diff options
author | Borislav Petkov <borislav.petkov@amd.com> | 2010-12-30 16:10:12 -0500 |
---|---|---|
committer | Borislav Petkov <borislav.petkov@amd.com> | 2011-02-09 10:05:33 -0500 |
commit | 10de52d6655ef0d4a1b8d2804db30208c26601ed (patch) | |
tree | f64dc00605b9ca41c264a6d3aecc717607d3975e /arch/x86/kernel/microcode_amd.c | |
parent | ffc7e8ac820bf9dd6106b01d3e64fecb5177cf43 (diff) |
x86, microcode, AMD: Simplify install_equiv_cpu_table
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>
Diffstat (limited to 'arch/x86/kernel/microcode_amd.c')
-rw-r--r-- | 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 ef91df0fb64d..9a451d7182f0 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) | |||
188 | 188 | ||
189 | static int install_equiv_cpu_table(const u8 *buf) | 189 | static int install_equiv_cpu_table(const u8 *buf) |
190 | { | 190 | { |
191 | u8 *container_hdr[UCODE_CONTAINER_HEADER_SIZE]; | 191 | unsigned int *ibuf = (unsigned int *)buf; |
192 | unsigned int *buf_pos = (unsigned int *)container_hdr; | 192 | unsigned int type = ibuf[1]; |
193 | unsigned long size; | 193 | unsigned int size = ibuf[2]; |
194 | 194 | ||
195 | get_ucode_data(&container_hdr, buf, UCODE_CONTAINER_HEADER_SIZE); | 195 | if (type != UCODE_EQUIV_CPU_TABLE_TYPE || !size) { |
196 | |||
197 | size = buf_pos[2]; | ||
198 | |||
199 | if (buf_pos[1] != UCODE_EQUIV_CPU_TABLE_TYPE || !size) { | ||
200 | pr_err("error: invalid type field in container file section header\n"); | 196 | pr_err("error: invalid type field in container file section header\n"); |
201 | return 0; | 197 | return -EINVAL; |
202 | } | 198 | } |
203 | 199 | ||
204 | equiv_cpu_table = vmalloc(size); | 200 | equiv_cpu_table = vmalloc(size); |
205 | if (!equiv_cpu_table) { | 201 | if (!equiv_cpu_table) { |
206 | pr_err("failed to allocate equivalent CPU table\n"); | 202 | pr_err("failed to allocate equivalent CPU table\n"); |
207 | return 0; | 203 | return -ENOMEM; |
208 | } | 204 | } |
209 | 205 | ||
210 | buf += UCODE_CONTAINER_HEADER_SIZE; | 206 | get_ucode_data(equiv_cpu_table, buf + UCODE_CONTAINER_HEADER_SIZE, size); |
211 | get_ucode_data(equiv_cpu_table, buf, size); | ||
212 | 207 | ||
213 | return size + UCODE_CONTAINER_HEADER_SIZE; /* add header length */ | 208 | return size + UCODE_CONTAINER_HEADER_SIZE; /* add header length */ |
214 | } | 209 | } |
@@ -232,7 +227,7 @@ generic_load_microcode(int cpu, const u8 *data, size_t size) | |||
232 | enum ucode_state state = UCODE_OK; | 227 | enum ucode_state state = UCODE_OK; |
233 | 228 | ||
234 | offset = install_equiv_cpu_table(ucode_ptr); | 229 | offset = install_equiv_cpu_table(ucode_ptr); |
235 | if (!offset) { | 230 | if (offset < 0) { |
236 | pr_err("failed to create equivalent cpu table\n"); | 231 | pr_err("failed to create equivalent cpu table\n"); |
237 | return UCODE_ERROR; | 232 | return UCODE_ERROR; |
238 | } | 233 | } |