Add a NULL pointer check in ttm_resource_manager_usage() to prevent
kernel NULL pointer dereferences when the function is called with
an uninitialized resource manager.
This fixes a kernel OOPS observed on APU devices where the VRAM
resource manager is not fully initialized, but various sysfs and
debug interfaces still attempt to query VRAM usage statistics.
The crash backtrace showed:
BUG: kernel NULL pointer dereference, address: 00000000000008f8
Call Trace:
amdttm_resource_manager_usage+0x1f/0x40 [amdttm]
amdgpu_mem_info_vram_used_show+0x1e/0x40 [amdgpu]
dev_attr_show+0x1d/0x40
kernfs_seq_show+0x27/0x30
By returning 0 for NULL managers, we allow callers to safely query
usage information even when the underlying resource manager is not
available, which is the expected behavior for devices without
dedicated VRAM like APUs.
Suggested-by: Philip Yang <[email protected]>
Signed-off-by: Jesse Zhang <[email protected]>
---
drivers/gpu/drm/ttm/ttm_resource.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c
b/drivers/gpu/drm/ttm/ttm_resource.c
index e2c82ad07eb4..e4d45f75e40a 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -587,6 +587,9 @@ uint64_t ttm_resource_manager_usage(struct
ttm_resource_manager *man)
{
uint64_t usage;
+ if (!man)
+ return 0;
+
spin_lock(&man->bdev->lru_lock);
usage = man->usage;
spin_unlock(&man->bdev->lru_lock);
--
2.49.0