[bug report] drm/ttm, drm_xe, Implement ttm_lru_walk_for_evict() using the guarded LRU iteration

Dan Carpenter dan.carpenter at linaro.org
Tue Jul 1 17:49:44 UTC 2025


Hello Thomas Hellström,

Commit bb8aa27eff6f ("drm/ttm, drm_xe, Implement
ttm_lru_walk_for_evict() using the guarded LRU iteration") from Jun
23, 2025 (linux-next), leads to the following Smatch static checker
warning:

	drivers/gpu/drm/ttm/ttm_bo_util.c:899 ttm_lru_walk_for_evict()
	warn: 'bo' isn't an ERR_PTR

drivers/gpu/drm/ttm/ttm_bo_util.c
   883  s64 ttm_lru_walk_for_evict(struct ttm_lru_walk *walk, struct ttm_device *bdev,
   884                             struct ttm_resource_manager *man, s64 target)
   885  {
   886          struct ttm_bo_lru_cursor cursor;
   887          struct ttm_buffer_object *bo;
   888          s64 progress = 0;
   889          s64 lret;
   890  
   891          ttm_bo_lru_for_each_reserved_guarded(&cursor, man, &walk->arg, bo) {
   892                  lret = walk->ops->process_bo(walk, bo);
   893                  if (lret == -EBUSY || lret == -EALREADY)
   894                          lret = 0;
   895                  progress = (lret < 0) ? lret : progress + lret;
   896                  if (progress < 0 || progress >= target)
   897                          break;
   898          }
   899          if (IS_ERR(bo))
   900                  return PTR_ERR(bo);

The ttm_bo_lru_for_each_reserved_guarded() macro checks for IS_ERR_OR_NULL()
but it can only be NULL.  These things are a bit frustrating to me because
when a function returns both error pointers and NULL then ideally there is a
reason for that and it should be documented.  "This function returns error
pointers if there is an error (kmalloc failed etc) or NULL if the object is
not found".

https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/

   901  
   902          return progress;

It's strange to me that we returns progress values which are greater than the
target value.

   903  }

regards,
dan carpenter


More information about the dri-devel mailing list