[PATCH 1/3] x86/microcode/AMD: Return bool from find_blobs_in_containers()

Nikolay Borisov posted 3 patches 1 month, 1 week ago
[PATCH 1/3] x86/microcode/AMD: Return bool from find_blobs_in_containers()
Posted by Nikolay Borisov 1 month, 1 week ago
Instead of open-coding the check for size/data move it inside the
function and make it return a boolean indicating whether data was found
or not. No functional changes.

Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
---
 arch/x86/kernel/cpu/microcode/amd.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index f63b051f25a0..9986cb85c951 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -554,7 +554,7 @@ static bool get_builtin_microcode(struct cpio_data *cp)
 	return false;
 }
 
-static void __init find_blobs_in_containers(struct cpio_data *ret)
+static bool __init find_blobs_in_containers(struct cpio_data *ret)
 {
 	struct cpio_data cp;
 
@@ -562,6 +562,7 @@ static void __init find_blobs_in_containers(struct cpio_data *ret)
 		cp = find_microcode_in_initrd(ucode_path);
 
 	*ret = cp;
+	return cp.data && cp.size;
 }
 
 void __init load_ucode_amd_bsp(struct early_load_data *ed, unsigned int cpuid_1_eax)
@@ -576,8 +577,7 @@ void __init load_ucode_amd_bsp(struct early_load_data *ed, unsigned int cpuid_1_
 	/* Needed in load_microcode_amd() */
 	ucode_cpu_info[0].cpu_sig.sig = cpuid_1_eax;
 
-	find_blobs_in_containers(&cp);
-	if (!(cp.data && cp.size))
+	if (!find_blobs_in_containers(&cp))
 		return;
 
 	if (early_apply_microcode(ed->old_rev, cp.data, cp.size))
@@ -597,8 +597,7 @@ static int __init save_microcode_in_initrd(void)
 	if (dis_ucode_ldr || c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10)
 		return 0;
 
-	find_blobs_in_containers(&cp);
-	if (!(cp.data && cp.size))
+	if (!find_blobs_in_containers(&cp))
 		return -EINVAL;
 
 	scan_containers(cp.data, cp.size, &desc);
-- 
2.34.1
Re: [PATCH 1/3] x86/microcode/AMD: Return bool from find_blobs_in_containers()
Posted by Borislav Petkov 1 week, 4 days ago
On Fri, Oct 18, 2024 at 06:51:49PM +0300, Nikolay Borisov wrote:
> @@ -562,6 +562,7 @@ static void __init find_blobs_in_containers(struct cpio_data *ret)
>  		cp = find_microcode_in_initrd(ucode_path);
>  
>  	*ret = cp;
> +	return cp.data && cp.size;

I guess we want this here ontop:

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 41b6f8a9e7e6..dfad4b26a662 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -561,12 +561,16 @@ static bool get_builtin_microcode(struct cpio_data *cp)
 static bool __init find_blobs_in_containers(struct cpio_data *ret)
 {
 	struct cpio_data cp;
+	bool found;
 
 	if (!get_builtin_microcode(&cp))
 		cp = find_microcode_in_initrd(ucode_path);
 
-	*ret = cp;
-	return cp.data && cp.size;
+	found = cp.data && cp.size;
+	if (found)
+		*ret = cp;
+
+	return found;
 }
 
 void __init load_ucode_amd_bsp(struct early_load_data *ed, unsigned int cpuid_1_eax)

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette