@@ -283,13 +283,13 @@ __verify_patch_section(const u8 *buf, size_t buf_size, u32 *sh_psize)
283
283
* exceed the per-family maximum). @sh_psize is the size read from the section
284
284
* header.
285
285
*/
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 )
287
287
{
288
288
u8 family = x86_family (bsp_cpuid_1_eax );
289
289
u32 max_size ;
290
290
291
291
if (family >= 0x15 )
292
- return min_t ( u32 , sh_psize , buf_size ) ;
292
+ goto ret ;
293
293
294
294
#define F1XH_MPB_MAX_SIZE 2048
295
295
#define F14H_MPB_MAX_SIZE 1824
@@ -303,13 +303,15 @@ static unsigned int __verify_patch_size(u32 sh_psize, size_t buf_size)
303
303
break ;
304
304
default :
305
305
WARN (1 , "%s: WTF family: 0x%x\n" , __func__ , family );
306
- return 0 ;
306
+ return false ;
307
307
}
308
308
309
- if (sh_psize > min_t ( u32 , buf_size , max_size ) )
310
- return 0 ;
309
+ if (sh_psize > max_size )
310
+ return false ;
311
311
312
- return sh_psize ;
312
+ ret :
313
+ /* Working with the whole buffer so < is ok. */
314
+ return sh_psize <= buf_size ;
313
315
}
314
316
315
317
/*
@@ -324,7 +326,6 @@ static int verify_patch(const u8 *buf, size_t buf_size, u32 *patch_size)
324
326
{
325
327
u8 family = x86_family (bsp_cpuid_1_eax );
326
328
struct microcode_header_amd * mc_hdr ;
327
- unsigned int ret ;
328
329
u32 sh_psize ;
329
330
u16 proc_id ;
330
331
u8 patch_fam ;
@@ -348,8 +349,7 @@ static int verify_patch(const u8 *buf, size_t buf_size, u32 *patch_size)
348
349
return -1 ;
349
350
}
350
351
351
- ret = __verify_patch_size (sh_psize , buf_size );
352
- if (!ret ) {
352
+ if (!__verify_patch_size (sh_psize , buf_size )) {
353
353
pr_debug ("Per-family patch size mismatch.\n" );
354
354
return -1 ;
355
355
}
@@ -381,8 +381,8 @@ static bool mc_patch_matches(struct microcode_amd *mc, u16 eq_id)
381
381
382
382
/*
383
383
* 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
+ *
386
386
* Returns the amount of bytes consumed while scanning. @desc contains all the
387
387
* data we're going to use in later stages of the application.
388
388
*/
@@ -484,7 +484,7 @@ static void scan_containers(u8 *ucode, size_t size, struct cont_desc *desc)
484
484
}
485
485
}
486
486
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 )
488
488
{
489
489
unsigned long p_addr = (unsigned long )& mc -> hdr .data_code ;
490
490
u32 rev , dummy ;
@@ -508,9 +508,9 @@ static int __apply_microcode_amd(struct microcode_amd *mc, unsigned int psize)
508
508
native_rdmsr (MSR_AMD64_PATCH_LEVEL , rev , dummy );
509
509
510
510
if (rev != mc -> hdr .patch_id )
511
- return -1 ;
511
+ return false ;
512
512
513
- return 0 ;
513
+ return true ;
514
514
}
515
515
516
516
/*
@@ -528,23 +528,22 @@ static bool early_apply_microcode(u32 old_rev, void *ucode, size_t size)
528
528
{
529
529
struct cont_desc desc = { 0 };
530
530
struct microcode_amd * mc ;
531
- bool ret = false;
532
531
533
532
scan_containers (ucode , size , & desc );
534
533
535
534
mc = desc .mc ;
536
535
if (!mc )
537
- return ret ;
536
+ return false ;
538
537
539
538
/*
540
539
* Allow application of the same revision to pick up SMT-specific
541
540
* changes even if the revision of the other SMT thread is already
542
541
* up-to-date.
543
542
*/
544
543
if (old_rev > mc -> hdr .patch_id )
545
- return ret ;
544
+ return false ;
546
545
547
- return ! __apply_microcode_amd (mc , desc .psize );
546
+ return __apply_microcode_amd (mc , desc .psize );
548
547
}
549
548
550
549
static bool get_builtin_microcode (struct cpio_data * cp )
@@ -569,14 +568,19 @@ static bool get_builtin_microcode(struct cpio_data *cp)
569
568
return false;
570
569
}
571
570
572
- static void __init find_blobs_in_containers (struct cpio_data * ret )
571
+ static bool __init find_blobs_in_containers (struct cpio_data * ret )
573
572
{
574
573
struct cpio_data cp ;
574
+ bool found ;
575
575
576
576
if (!get_builtin_microcode (& cp ))
577
577
cp = find_microcode_in_initrd (ucode_path );
578
578
579
- * ret = cp ;
579
+ found = cp .data && cp .size ;
580
+ if (found )
581
+ * ret = cp ;
582
+
583
+ return found ;
580
584
}
581
585
582
586
void __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_
591
595
/* Needed in load_microcode_amd() */
592
596
ucode_cpu_info [0 ].cpu_sig .sig = cpuid_1_eax ;
593
597
594
- find_blobs_in_containers (& cp );
595
- if (!(cp .data && cp .size ))
598
+ if (!find_blobs_in_containers (& cp ))
596
599
return ;
597
600
598
601
if (early_apply_microcode (ed -> old_rev , cp .data , cp .size ))
@@ -612,8 +615,7 @@ static int __init save_microcode_in_initrd(void)
612
615
if (dis_ucode_ldr || c -> x86_vendor != X86_VENDOR_AMD || c -> x86 < 0x10 )
613
616
return 0 ;
614
617
615
- find_blobs_in_containers (& cp );
616
- if (!(cp .data && cp .size ))
618
+ if (!find_blobs_in_containers (& cp ))
617
619
return - EINVAL ;
618
620
619
621
scan_containers (cp .data , cp .size , & desc );
@@ -760,7 +762,7 @@ void reload_ucode_amd(unsigned int cpu)
760
762
rdmsr (MSR_AMD64_PATCH_LEVEL , rev , dummy );
761
763
762
764
if (rev < mc -> hdr .patch_id ) {
763
- if (! __apply_microcode_amd (mc , p -> size ))
765
+ if (__apply_microcode_amd (mc , p -> size ))
764
766
pr_info_once ("reload revision: 0x%08x\n" , mc -> hdr .patch_id );
765
767
}
766
768
}
@@ -813,7 +815,7 @@ static enum ucode_state apply_microcode_amd(int cpu)
813
815
goto out ;
814
816
}
815
817
816
- if (__apply_microcode_amd (mc_amd , p -> size )) {
818
+ if (! __apply_microcode_amd (mc_amd , p -> size )) {
817
819
pr_err ("CPU%d: update failed for patch_level=0x%08x\n" ,
818
820
cpu , mc_amd -> hdr .patch_id );
819
821
return UCODE_ERROR ;
0 commit comments