Commit d8317f3d authored by Nikolay Borisov's avatar Nikolay Borisov Committed by Borislav Petkov (AMD)
Browse files

x86/microcode/AMD: Make __verify_patch_size() return bool



The result of that function is in essence boolean, so simplify to return the
result of the relevant expression. It also makes it follow the convention used
by __verify_patch_section().

No functional changes.

Signed-off-by: default avatarNikolay Borisov <nik.borisov@suse.com>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20241018155151.702350-3-nik.borisov@suse.com
parent db80b2ef
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -283,13 +283,13 @@ __verify_patch_section(const u8 *buf, size_t buf_size, u32 *sh_psize)
 * exceed the per-family maximum). @sh_psize is the size read from the section
 * header.
 */
static unsigned int __verify_patch_size(u32 sh_psize, size_t buf_size)
static bool __verify_patch_size(u32 sh_psize, size_t buf_size)
{
	u8 family = x86_family(bsp_cpuid_1_eax);
	u32 max_size;

	if (family >= 0x15)
		return min_t(u32, sh_psize, buf_size);
		goto ret;

#define F1XH_MPB_MAX_SIZE 2048
#define F14H_MPB_MAX_SIZE 1824
@@ -303,13 +303,15 @@ static unsigned int __verify_patch_size(u32 sh_psize, size_t buf_size)
		break;
	default:
		WARN(1, "%s: WTF family: 0x%x\n", __func__, family);
		return 0;
		return false;
	}

	if (sh_psize > min_t(u32, buf_size, max_size))
		return 0;
	if (sh_psize > max_size)
		return false;

	return sh_psize;
ret:
	/* Working with the whole buffer so < is ok. */
	return sh_psize <= buf_size;
}

/*
@@ -324,7 +326,6 @@ static int verify_patch(const u8 *buf, size_t buf_size, u32 *patch_size)
{
	u8 family = x86_family(bsp_cpuid_1_eax);
	struct microcode_header_amd *mc_hdr;
	unsigned int ret;
	u32 sh_psize;
	u16 proc_id;
	u8 patch_fam;
@@ -348,8 +349,7 @@ static int verify_patch(const u8 *buf, size_t buf_size, u32 *patch_size)
		return -1;
	}

	ret = __verify_patch_size(sh_psize, buf_size);
	if (!ret) {
	if (!__verify_patch_size(sh_psize, buf_size)) {
		pr_debug("Per-family patch size mismatch.\n");
		return -1;
	}