Skip to content

Commit ffc7e8a

Browse files
author
Borislav Petkov
committed
x86, microcode, AMD: Release firmware on error
When the ucode magic is wrong, for whatever reason, we don't release the loaded firmware binary and its related resources. Make sure we do. Also, fix function naming to fit this driver's convention and shorten variable names. Signed-off-by: Borislav Petkov <borislav.petkov@amd.com> Acked-by: Andreas Herrmann <Andreas.Herrmann3@amd.com>
1 parent 6c53cbf commit ffc7e8a

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

‎arch/x86/kernel/microcode_amd.c‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,27 +278,29 @@ generic_load_microcode(int cpu, const u8 *data, size_t size)
278278
return state;
279279
}
280280

281-
static enum ucode_state request_microcode_fw(int cpu, struct device *device)
281+
static enum ucode_state request_microcode_amd(int cpu, struct device *device)
282282
{
283283
const char *fw_name = "amd-ucode/microcode_amd.bin";
284-
const struct firmware *firmware;
285-
enum ucode_state ret;
284+
const struct firmware *fw;
285+
enum ucode_state ret = UCODE_NFOUND;
286286

287-
if (request_firmware(&firmware, fw_name, device)) {
287+
if (request_firmware(&fw, fw_name, device)) {
288288
printk(KERN_ERR "microcode: failed to load file %s\n", fw_name);
289-
return UCODE_NFOUND;
289+
goto out;
290290
}
291291

292-
if (*(u32 *)firmware->data != UCODE_MAGIC) {
293-
pr_err("invalid UCODE_MAGIC (0x%08x)\n",
294-
*(u32 *)firmware->data);
295-
return UCODE_ERROR;
292+
ret = UCODE_ERROR;
293+
if (*(u32 *)fw->data != UCODE_MAGIC) {
294+
pr_err("Invalid UCODE_MAGIC (0x%08x)\n", *(u32 *)fw->data);
295+
goto fw_release;
296296
}
297297

298-
ret = generic_load_microcode(cpu, firmware->data, firmware->size);
298+
ret = generic_load_microcode(cpu, fw->data, fw->size);
299299

300-
release_firmware(firmware);
300+
fw_release:
301+
release_firmware(fw);
301302

303+
out:
302304
return ret;
303305
}
304306

@@ -319,7 +321,7 @@ static void microcode_fini_cpu_amd(int cpu)
319321

320322
static struct microcode_ops microcode_amd_ops = {
321323
.request_microcode_user = request_microcode_user,
322-
.request_microcode_fw = request_microcode_fw,
324+
.request_microcode_fw = request_microcode_amd,
323325
.collect_cpu_info = collect_cpu_info_amd,
324326
.apply_microcode = apply_microcode_amd,
325327
.microcode_fini_cpu = microcode_fini_cpu_amd,

0 commit comments

Comments
 (0)