drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:473 amdgpu_bo_validate_size() error: we previously assumed 'man' could be null (see line 458)

From: Dan Carpenter
Date: Tue Jan 03 2023 - 03:01:30 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 1b929c02afd37871d5afb9d498426f83432e71c2
commit: 7554886daa31eacc8e7fac9e15bbce67d10b8f1f drm/amdgpu: Fix size validation for non-exclusive domains (v4)
config: ia64-randconfig-m041-20221229
compiler: ia64-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>

smatch warnings:
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:473 amdgpu_bo_validate_size() error: we previously assumed 'man' could be null (see line 458)

vim +/man +473 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c

79c631239a83ae Andrey Grodzovsky 2017-11-10 444 static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
79c631239a83ae Andrey Grodzovsky 2017-11-10 445 unsigned long size, u32 domain)
79c631239a83ae Andrey Grodzovsky 2017-11-10 446 {
9de59bc201496f Dave Airlie 2020-08-04 447 struct ttm_resource_manager *man = NULL;
79c631239a83ae Andrey Grodzovsky 2017-11-10 448
79c631239a83ae Andrey Grodzovsky 2017-11-10 449 /*
79c631239a83ae Andrey Grodzovsky 2017-11-10 450 * If GTT is part of requested domains the check must succeed to
7554886daa31ea Luben Tuikov 2022-12-10 451 * allow fall back to GTT.
79c631239a83ae Andrey Grodzovsky 2017-11-10 452 */
79c631239a83ae Andrey Grodzovsky 2017-11-10 453 if (domain & AMDGPU_GEM_DOMAIN_GTT) {
6c28aed6e5b7fa Dave Airlie 2020-08-04 454 man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
79c631239a83ae Andrey Grodzovsky 2017-11-10 455
7554886daa31ea Luben Tuikov 2022-12-10 456 if (man && size < man->size)
79c631239a83ae Andrey Grodzovsky 2017-11-10 457 return true;
7554886daa31ea Luben Tuikov 2022-12-10 @458 else if (!man)
7554886daa31ea Luben Tuikov 2022-12-10 459 WARN_ON_ONCE("GTT domain requested but GTT mem manager uninitialized");

WARN()

79c631239a83ae Andrey Grodzovsky 2017-11-10 460 goto fail;
7554886daa31ea Luben Tuikov 2022-12-10 461 } else if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
6c28aed6e5b7fa Dave Airlie 2020-08-04 462 man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
79c631239a83ae Andrey Grodzovsky 2017-11-10 463
7554886daa31ea Luben Tuikov 2022-12-10 464 if (man && size < man->size)
79c631239a83ae Andrey Grodzovsky 2017-11-10 465 return true;
79c631239a83ae Andrey Grodzovsky 2017-11-10 466 goto fail;
79c631239a83ae Andrey Grodzovsky 2017-11-10 467 }
79c631239a83ae Andrey Grodzovsky 2017-11-10 468
79c631239a83ae Andrey Grodzovsky 2017-11-10 469 /* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU */
79c631239a83ae Andrey Grodzovsky 2017-11-10 470 return true;
79c631239a83ae Andrey Grodzovsky 2017-11-10 471
79c631239a83ae Andrey Grodzovsky 2017-11-10 472 fail:
299c776cebb01c Michel Dänzer 2017-11-15 @473 DRM_DEBUG("BO size %lu > total memory in domain: %llu\n", size,
4499c90e902f39 Christian König 2022-03-11 474 man->size);

Followed by crash.

79c631239a83ae Andrey Grodzovsky 2017-11-10 475 return false;
79c631239a83ae Andrey Grodzovsky 2017-11-10 476 }

--
0-DAY CI Kernel Test Service
https://01.org/lkp