Skip to content

Commit d8317f3

Browse files
Nikolay Borisovbp3tk0v
authored andcommitted
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: Nikolay Borisov <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent db80b2e commit d8317f3

File tree

1 file changed

+9
-9
lines changed
  • arch/x86/kernel/cpu/microcode

1 file changed

+9
-9
lines changed

arch/x86/kernel/cpu/microcode/amd.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ __verify_patch_section(const u8 *buf, size_t buf_size, u32 *sh_psize)
283283
* exceed the per-family maximum). @sh_psize is the size read from the section
284284
* header.
285285
*/
286-
static unsigned int __verify_patch_size(u32 sh_psize, size_t buf_size)
286+
static bool __verify_patch_size(u32 sh_psize, size_t buf_size)
287287
{
288288
u8 family = x86_family(bsp_cpuid_1_eax);
289289
u32 max_size;
290290

291291
if (family >= 0x15)
292-
return min_t(u32, sh_psize, buf_size);
292+
goto ret;
293293

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

309-
if (sh_psize > min_t(u32, buf_size, max_size))
310-
return 0;
309+
if (sh_psize > max_size)
310+
return false;
311311

312-
return sh_psize;
312+
ret:
313+
/* Working with the whole buffer so < is ok. */
314+
return sh_psize <= buf_size;
313315
}
314316

315317
/*
@@ -324,7 +326,6 @@ static int verify_patch(const u8 *buf, size_t buf_size, u32 *patch_size)
324326
{
325327
u8 family = x86_family(bsp_cpuid_1_eax);
326328
struct microcode_header_amd *mc_hdr;
327-
unsigned int ret;
328329
u32 sh_psize;
329330
u16 proc_id;
330331
u8 patch_fam;
@@ -348,8 +349,7 @@ static int verify_patch(const u8 *buf, size_t buf_size, u32 *patch_size)
348349
return -1;
349350
}
350351

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

0 commit comments

Comments
 (0)