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

drm/amdgpu: Do not directly dereference pointers to BIOS area.

Use readb() and memcpy_fromio() accessors instead.

Ported from radeon commit:
f2c9e560b406f2f6b14b345c7da33467dee9cdf2

Acked-by: Christian König <christian.koenig@amd.com>
Acked-by: Jammy Zhou <Jammy.Zhou@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

+7 -3
+7 -3
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
··· 75 75 76 76 bool amdgpu_read_bios(struct amdgpu_device *adev) 77 77 { 78 - uint8_t __iomem *bios; 78 + uint8_t __iomem *bios, val1, val2; 79 79 size_t size; 80 80 81 81 adev->bios = NULL; ··· 85 85 return false; 86 86 } 87 87 88 - if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) { 88 + val1 = readb(&bios[0]); 89 + val2 = readb(&bios[1]); 90 + 91 + if (size == 0 || val1 != 0x55 || val2 != 0xaa) { 89 92 pci_unmap_rom(adev->pdev, bios); 90 93 return false; 91 94 } 92 - adev->bios = kmemdup(bios, size, GFP_KERNEL); 95 + adev->bios = kzalloc(size, GFP_KERNEL); 93 96 if (adev->bios == NULL) { 94 97 pci_unmap_rom(adev->pdev, bios); 95 98 return false; 96 99 } 100 + memcpy_fromio(adev->bios, bios, size); 97 101 pci_unmap_rom(adev->pdev, bios); 98 102 return true; 99 103 }