From 3f7b312e89c47e4c458961e3e4863ce4aec9ae3e Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Fri, 9 Nov 2018 10:26:22 -0800 Subject: [PATCH] gpu: nvgpu: Adjust error condition checking in pd_alloc code The following error checking code in nvgpu_pd_cache_alloc() cannot hit the greater than PAGE_SIZE check: if ((bytes & (bytes - 1U)) != 0U || (bytes >= PAGE_SIZE || bytes < NVGPU_PD_CACHE_MIN)) { /* ... */ This is because the nvgpu_pd_cache_alloc() function is only called, specifically when, bytes is less than PAGE_SIZE! As such we would only see this case when there's a bug. So change the error condition to now check only for bytes being a power of 2 and being greater than NVGPU_PD_CACHE_MIN. The greater than page size check has been turned into an assert since this should really never happen in practice unless there's a bug. JIRA NVGPU-1323 Change-Id: I97cd701aa4f045345606b90c97a8478b4a06e189 Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1946731 Reviewed-by: Terje Bergstrom Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/mm/pd_cache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/nvgpu/common/mm/pd_cache.c b/drivers/gpu/nvgpu/common/mm/pd_cache.c index 3ce8d40c1..a58a6759f 100644 --- a/drivers/gpu/nvgpu/common/mm/pd_cache.c +++ b/drivers/gpu/nvgpu/common/mm/pd_cache.c @@ -389,12 +389,13 @@ static int nvgpu_pd_cache_alloc(struct gk20a *g, struct nvgpu_pd_cache *cache, pd_dbg(g, "PD-Alloc [C] %u bytes", bytes); if ((bytes & (bytes - 1U)) != 0U || - (bytes >= PAGE_SIZE || - bytes < NVGPU_PD_CACHE_MIN)) { + bytes < NVGPU_PD_CACHE_MIN) { pd_dbg(g, "PD-Alloc [C] Invalid (bytes=%u)!", bytes); return -EINVAL; } + nvgpu_assert(bytes < PAGE_SIZE); + pentry = nvgpu_pd_cache_get_partial(cache, bytes); if (pentry == NULL) { err = nvgpu_pd_cache_alloc_new(g, cache, pd, bytes);