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 <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1946731
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Alex Waterman
2018-11-09 10:26:22 -08:00
committed by mobile promotions
parent b646148318
commit 3f7b312e89

View File

@@ -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);