Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: Fix vbios build number parsing logic

It's not necessary that the build string and atom header section has a
difference of 32 bytes. Use the remaining bytes in the section as copy
limit.

Fixes: d6fa80266178 ("drm/amdgpu: Add vbios build number interface")
Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Lijo Lazar and committed by
Alex Deucher
b29c22b8 342f141b

+4 -3
+4 -3
drivers/gpu/drm/amd/amdgpu/atom.c
··· 1502 1502 { 1503 1503 unsigned char *atom_rom_hdr; 1504 1504 unsigned char *str; 1505 - uint16_t base; 1505 + uint16_t base, len; 1506 1506 1507 1507 base = CU16(ATOM_ROM_TABLE_PTR); 1508 1508 atom_rom_hdr = CSTR(base); ··· 1515 1515 while (str < atom_rom_hdr && *str++) 1516 1516 ; 1517 1517 1518 - if ((str + STRLEN_NORMAL) < atom_rom_hdr) 1519 - strscpy(ctx->build_num, str, STRLEN_NORMAL); 1518 + len = min(atom_rom_hdr - str, STRLEN_NORMAL); 1519 + if (len) 1520 + strscpy(ctx->build_num, str, len); 1520 1521 } 1521 1522 1522 1523 struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)