Skip to content

Commit 72dc571

Browse files
committed
x86/microcode/AMD: Fix container size's type
Make it size_t everywhere as this is what we get from cpio. [ bp: Fix a smatch warning. ] Originally-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name> Reported-by: kbuild test robot <lkp@intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20181107170218.7596-13-bp@alien8.de
1 parent c45e803 commit 72dc571

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

  • arch/x86/kernel/cpu/microcode

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ __verify_patch_section(const u8 *buf, size_t buf_size, u32 *sh_psize, bool early
186186
* exceed the per-family maximum). @sh_psize is the size read from the section
187187
* header.
188188
*/
189-
static unsigned int
190-
__verify_patch_size(u8 family, u32 sh_psize, unsigned int buf_size)
189+
static unsigned int __verify_patch_size(u8 family, u32 sh_psize, size_t buf_size)
191190
{
192191
u32 max_size;
193192

@@ -285,10 +284,10 @@ verify_patch(u8 family, const u8 *buf, size_t buf_size, u32 *patch_size, bool ea
285284
* Returns the amount of bytes consumed while scanning. @desc contains all the
286285
* data we're going to use in later stages of the application.
287286
*/
288-
static ssize_t parse_container(u8 *ucode, ssize_t size, struct cont_desc *desc)
287+
static size_t parse_container(u8 *ucode, size_t size, struct cont_desc *desc)
289288
{
290289
struct equiv_cpu_entry *eq;
291-
ssize_t orig_size = size;
290+
size_t orig_size = size;
292291
u32 *hdr = (u32 *)ucode;
293292
u16 eq_id;
294293
u8 *buf;
@@ -366,15 +365,18 @@ static ssize_t parse_container(u8 *ucode, ssize_t size, struct cont_desc *desc)
366365
*/
367366
static void scan_containers(u8 *ucode, size_t size, struct cont_desc *desc)
368367
{
369-
ssize_t rem = size;
370-
371-
while (rem >= 0) {
372-
ssize_t s = parse_container(ucode, rem, desc);
368+
while (size) {
369+
size_t s = parse_container(ucode, size, desc);
373370
if (!s)
374371
return;
375372

376-
ucode += s;
377-
rem -= s;
373+
/* catch wraparound */
374+
if (size >= s) {
375+
ucode += s;
376+
size -= s;
377+
} else {
378+
return;
379+
}
378380
}
379381
}
380382

0 commit comments

Comments
 (0)