diff options
author | Tom St Denis <tom.stdenis@amd.com> | 2019-06-14 11:47:21 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2019-06-20 12:32:24 -0400 |
commit | c1d827d62f71eb6eaa0b2ffad4d893faa99e4c87 (patch) | |
tree | 679895efa8a73ebb81278f758bbfde4ced465822 | |
parent | acb05f0a3f6261b330034e14e4d2c6b4bc896504 (diff) |
drm/amd/amdgpu: cast mem->num_pages to 64-bits when shifting (v2)
On 32-bit hosts mem->num_pages is 32-bits and can overflow
when shifted. Add a cast to avoid this.
(v2): Style fix.
Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c index c963ad86072e..1150e34bc28f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | |||
@@ -276,7 +276,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man, | |||
276 | struct drm_mm_node *nodes; | 276 | struct drm_mm_node *nodes; |
277 | enum drm_mm_insert_mode mode; | 277 | enum drm_mm_insert_mode mode; |
278 | unsigned long lpfn, num_nodes, pages_per_node, pages_left; | 278 | unsigned long lpfn, num_nodes, pages_per_node, pages_left; |
279 | uint64_t vis_usage = 0; | 279 | uint64_t vis_usage = 0, mem_bytes; |
280 | unsigned i; | 280 | unsigned i; |
281 | int r; | 281 | int r; |
282 | 282 | ||
@@ -285,8 +285,9 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man, | |||
285 | lpfn = man->size; | 285 | lpfn = man->size; |
286 | 286 | ||
287 | /* bail out quickly if there's likely not enough VRAM for this BO */ | 287 | /* bail out quickly if there's likely not enough VRAM for this BO */ |
288 | if (atomic64_add_return(mem->num_pages << PAGE_SHIFT, &mgr->usage) > adev->gmc.mc_vram_size) { | 288 | mem_bytes = (u64)mem->num_pages << PAGE_SHIFT; |
289 | atomic64_sub(mem->num_pages << PAGE_SHIFT, &mgr->usage); | 289 | if (atomic64_add_return(mem_bytes, &mgr->usage) > adev->gmc.mc_vram_size) { |
290 | atomic64_sub(mem_bytes, &mgr->usage); | ||
290 | mem->mm_node = NULL; | 291 | mem->mm_node = NULL; |
291 | return 0; | 292 | return 0; |
292 | } | 293 | } |
@@ -308,7 +309,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man, | |||
308 | nodes = kvmalloc_array((uint32_t)num_nodes, sizeof(*nodes), | 309 | nodes = kvmalloc_array((uint32_t)num_nodes, sizeof(*nodes), |
309 | GFP_KERNEL | __GFP_ZERO); | 310 | GFP_KERNEL | __GFP_ZERO); |
310 | if (!nodes) { | 311 | if (!nodes) { |
311 | atomic64_sub(mem->num_pages << PAGE_SHIFT, &mgr->usage); | 312 | atomic64_sub(mem_bytes, &mgr->usage); |
312 | return -ENOMEM; | 313 | return -ENOMEM; |
313 | } | 314 | } |
314 | 315 | ||