diff options
author | Evan Quan <evan.quan@amd.com> | 2018-05-29 04:31:05 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2018-06-13 14:45:24 -0400 |
commit | cb5ed37f1f9976a5f9d5f677ac9423642e30d10f (patch) | |
tree | a77c32929aa5e512e3237877c199693c22a12f7e /drivers/gpu/drm/amd/amdgpu | |
parent | b0f6b8090e05a24263207a399b6c48a94034f1e8 (diff) |
drm/amdgpu: fix parsing indirect register list v2
WARN_ON possible buffer overflow and avoid unnecessary dereference.
v2: change BUG_ON to WARN_ON
Signed-off-by: Evan Quan <evan.quan@amd.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c index 95f2773dc11d..a69153435ea7 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | |||
@@ -1838,13 +1838,15 @@ static void gfx_v9_1_parse_ind_reg_list(int *register_list_format, | |||
1838 | int indirect_offset, | 1838 | int indirect_offset, |
1839 | int list_size, | 1839 | int list_size, |
1840 | int *unique_indirect_regs, | 1840 | int *unique_indirect_regs, |
1841 | int *unique_indirect_reg_count, | 1841 | int unique_indirect_reg_count, |
1842 | int *indirect_start_offsets, | 1842 | int *indirect_start_offsets, |
1843 | int *indirect_start_offsets_count) | 1843 | int *indirect_start_offsets_count, |
1844 | int max_start_offsets_count) | ||
1844 | { | 1845 | { |
1845 | int idx; | 1846 | int idx; |
1846 | 1847 | ||
1847 | for (; indirect_offset < list_size; indirect_offset++) { | 1848 | for (; indirect_offset < list_size; indirect_offset++) { |
1849 | WARN_ON(*indirect_start_offsets_count >= max_start_offsets_count); | ||
1848 | indirect_start_offsets[*indirect_start_offsets_count] = indirect_offset; | 1850 | indirect_start_offsets[*indirect_start_offsets_count] = indirect_offset; |
1849 | *indirect_start_offsets_count = *indirect_start_offsets_count + 1; | 1851 | *indirect_start_offsets_count = *indirect_start_offsets_count + 1; |
1850 | 1852 | ||
@@ -1852,14 +1854,14 @@ static void gfx_v9_1_parse_ind_reg_list(int *register_list_format, | |||
1852 | indirect_offset += 2; | 1854 | indirect_offset += 2; |
1853 | 1855 | ||
1854 | /* look for the matching indice */ | 1856 | /* look for the matching indice */ |
1855 | for (idx = 0; idx < *unique_indirect_reg_count; idx++) { | 1857 | for (idx = 0; idx < unique_indirect_reg_count; idx++) { |
1856 | if (unique_indirect_regs[idx] == | 1858 | if (unique_indirect_regs[idx] == |
1857 | register_list_format[indirect_offset] || | 1859 | register_list_format[indirect_offset] || |
1858 | !unique_indirect_regs[idx]) | 1860 | !unique_indirect_regs[idx]) |
1859 | break; | 1861 | break; |
1860 | } | 1862 | } |
1861 | 1863 | ||
1862 | BUG_ON(idx >= *unique_indirect_reg_count); | 1864 | BUG_ON(idx >= unique_indirect_reg_count); |
1863 | 1865 | ||
1864 | if (!unique_indirect_regs[idx]) | 1866 | if (!unique_indirect_regs[idx]) |
1865 | unique_indirect_regs[idx] = register_list_format[indirect_offset]; | 1867 | unique_indirect_regs[idx] = register_list_format[indirect_offset]; |
@@ -1894,9 +1896,10 @@ static int gfx_v9_1_init_rlc_save_restore_list(struct amdgpu_device *adev) | |||
1894 | adev->gfx.rlc.reg_list_format_direct_reg_list_length, | 1896 | adev->gfx.rlc.reg_list_format_direct_reg_list_length, |
1895 | adev->gfx.rlc.reg_list_format_size_bytes >> 2, | 1897 | adev->gfx.rlc.reg_list_format_size_bytes >> 2, |
1896 | unique_indirect_regs, | 1898 | unique_indirect_regs, |
1897 | &unique_indirect_reg_count, | 1899 | unique_indirect_reg_count, |
1898 | indirect_start_offsets, | 1900 | indirect_start_offsets, |
1899 | &indirect_start_offsets_count); | 1901 | &indirect_start_offsets_count, |
1902 | ARRAY_SIZE(indirect_start_offsets)); | ||
1900 | 1903 | ||
1901 | /* enable auto inc in case it is disabled */ | 1904 | /* enable auto inc in case it is disabled */ |
1902 | tmp = RREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_CNTL)); | 1905 | tmp = RREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_CNTL)); |