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>
This commit is contained in:
@@ -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)
|
static int install_equiv_cpu_table(const u8 *buf)
|
||||||
{
|
{
|
||||||
u8 *container_hdr[UCODE_CONTAINER_HEADER_SIZE];
|
unsigned int *ibuf = (unsigned int *)buf;
|
||||||
unsigned int *buf_pos = (unsigned int *)container_hdr;
|
unsigned int type = ibuf[1];
|
||||||
unsigned long size;
|
unsigned int size = ibuf[2];
|
||||||
|
|
||||||
get_ucode_data(&container_hdr, buf, UCODE_CONTAINER_HEADER_SIZE);
|
if (type != UCODE_EQUIV_CPU_TABLE_TYPE || !size) {
|
||||||
|
|
||||||
size = buf_pos[2];
|
|
||||||
|
|
||||||
if (buf_pos[1] != UCODE_EQUIV_CPU_TABLE_TYPE || !size) {
|
|
||||||
pr_err("error: invalid type field in container file section header\n");
|
pr_err("error: invalid type field in container file section header\n");
|
||||||
return 0;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
equiv_cpu_table = vmalloc(size);
|
equiv_cpu_table = vmalloc(size);
|
||||||
if (!equiv_cpu_table) {
|
if (!equiv_cpu_table) {
|
||||||
pr_err("failed to allocate equivalent CPU table\n");
|
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 + UCODE_CONTAINER_HEADER_SIZE, size);
|
||||||
get_ucode_data(equiv_cpu_table, buf, size);
|
|
||||||
|
|
||||||
return size + UCODE_CONTAINER_HEADER_SIZE; /* add header length */
|
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;
|
enum ucode_state state = UCODE_OK;
|
||||||
|
|
||||||
offset = install_equiv_cpu_table(ucode_ptr);
|
offset = install_equiv_cpu_table(ucode_ptr);
|
||||||
if (!offset) {
|
if (offset < 0) {
|
||||||
pr_err("failed to create equivalent cpu table\n");
|
pr_err("failed to create equivalent cpu table\n");
|
||||||
return UCODE_ERROR;
|
return UCODE_ERROR;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user