@@ -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 }
@@ -381,8 +381,8 @@ static bool mc_patch_matches(struct microcode_amd *mc, u16 eq_id)
381381
382382/*
383383 * This scans the ucode blob for the proper container as we can have multiple
384- * containers glued together. Returns the equivalence ID from the equivalence
385- * table or 0 if none found.
384+ * containers glued together.
385+ *
386386 * Returns the amount of bytes consumed while scanning. @desc contains all the
387387 * data we're going to use in later stages of the application.
388388 */
@@ -484,7 +484,7 @@ static void scan_containers(u8 *ucode, size_t size, struct cont_desc *desc)
484484 }
485485}
486486
487- static int __apply_microcode_amd (struct microcode_amd * mc , unsigned int psize )
487+ static bool __apply_microcode_amd (struct microcode_amd * mc , unsigned int psize )
488488{
489489 unsigned long p_addr = (unsigned long )& mc -> hdr .data_code ;
490490 u32 rev , dummy ;
@@ -508,9 +508,9 @@ static int __apply_microcode_amd(struct microcode_amd *mc, unsigned int psize)
508508 native_rdmsr (MSR_AMD64_PATCH_LEVEL , rev , dummy );
509509
510510 if (rev != mc -> hdr .patch_id )
511- return -1 ;
511+ return false ;
512512
513- return 0 ;
513+ return true ;
514514}
515515
516516/*
@@ -528,23 +528,22 @@ static bool early_apply_microcode(u32 old_rev, void *ucode, size_t size)
528528{
529529 struct cont_desc desc = { 0 };
530530 struct microcode_amd * mc ;
531- bool ret = false;
532531
533532 scan_containers (ucode , size , & desc );
534533
535534 mc = desc .mc ;
536535 if (!mc )
537- return ret ;
536+ return false ;
538537
539538 /*
540539 * Allow application of the same revision to pick up SMT-specific
541540 * changes even if the revision of the other SMT thread is already
542541 * up-to-date.
543542 */
544543 if (old_rev > mc -> hdr .patch_id )
545- return ret ;
544+ return false ;
546545
547- return ! __apply_microcode_amd (mc , desc .psize );
546+ return __apply_microcode_amd (mc , desc .psize );
548547}
549548
550549static bool get_builtin_microcode (struct cpio_data * cp )
@@ -569,14 +568,19 @@ static bool get_builtin_microcode(struct cpio_data *cp)
569568 return false;
570569}
571570
572- static void __init find_blobs_in_containers (struct cpio_data * ret )
571+ static bool __init find_blobs_in_containers (struct cpio_data * ret )
573572{
574573 struct cpio_data cp ;
574+ bool found ;
575575
576576 if (!get_builtin_microcode (& cp ))
577577 cp = find_microcode_in_initrd (ucode_path );
578578
579- * ret = cp ;
579+ found = cp .data && cp .size ;
580+ if (found )
581+ * ret = cp ;
582+
583+ return found ;
580584}
581585
582586void __init load_ucode_amd_bsp (struct early_load_data * ed , unsigned int cpuid_1_eax )
@@ -591,8 +595,7 @@ void __init load_ucode_amd_bsp(struct early_load_data *ed, unsigned int cpuid_1_
591595 /* Needed in load_microcode_amd() */
592596 ucode_cpu_info [0 ].cpu_sig .sig = cpuid_1_eax ;
593597
594- find_blobs_in_containers (& cp );
595- if (!(cp .data && cp .size ))
598+ if (!find_blobs_in_containers (& cp ))
596599 return ;
597600
598601 if (early_apply_microcode (ed -> old_rev , cp .data , cp .size ))
@@ -612,8 +615,7 @@ static int __init save_microcode_in_initrd(void)
612615 if (dis_ucode_ldr || c -> x86_vendor != X86_VENDOR_AMD || c -> x86 < 0x10 )
613616 return 0 ;
614617
615- find_blobs_in_containers (& cp );
616- if (!(cp .data && cp .size ))
618+ if (!find_blobs_in_containers (& cp ))
617619 return - EINVAL ;
618620
619621 scan_containers (cp .data , cp .size , & desc );
@@ -760,7 +762,7 @@ void reload_ucode_amd(unsigned int cpu)
760762 rdmsr (MSR_AMD64_PATCH_LEVEL , rev , dummy );
761763
762764 if (rev < mc -> hdr .patch_id ) {
763- if (! __apply_microcode_amd (mc , p -> size ))
765+ if (__apply_microcode_amd (mc , p -> size ))
764766 pr_info_once ("reload revision: 0x%08x\n" , mc -> hdr .patch_id );
765767 }
766768}
@@ -813,7 +815,7 @@ static enum ucode_state apply_microcode_amd(int cpu)
813815 goto out ;
814816 }
815817
816- if (__apply_microcode_amd (mc_amd , p -> size )) {
818+ if (! __apply_microcode_amd (mc_amd , p -> size )) {
817819 pr_err ("CPU%d: update failed for patch_level=0x%08x\n" ,
818820 cpu , mc_amd -> hdr .patch_id );
819821 return UCODE_ERROR ;
0 commit comments