[PATCH 2/2] amdgpu: don't dereference a NULL resource in sysfs code

Christian König ckoenig.leichtzumerken at gmail.com
Thu Jun 6 07:14:05 UTC 2024


Am 03.06.24 um 10:46 schrieb Pierre-Eric Pelloux-Prayer:
> dma_resv_trylock being successful doesn't guarantee that bo->tbo.base.resv
> is not NULL, so check its validity before using it.
>
> Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>

Please make sure that checkpatch doesn't complain about anything.

With that done the patch is Reviewed-by: Christian König 
<christian.koenig at amd.com>

Regards,
Christian.

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 63 +++++++++++-----------
>   1 file changed, 33 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 1eadcad1856d..6faeb9e4a572 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -1594,36 +1594,39 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)
>   	u64 size;
>   
>   	if (dma_resv_trylock(bo->tbo.base.resv)) {
> -
> -		switch (bo->tbo.resource->mem_type) {
> -		case TTM_PL_VRAM:
> -			if (amdgpu_res_cpu_visible(adev, bo->tbo.resource))
> -				placement = "VRAM VISIBLE";
> -			else
> -				placement = "VRAM";
> -			break;
> -		case TTM_PL_TT:
> -			placement = "GTT";
> -			break;
> -		case AMDGPU_PL_GDS:
> -			placement = "GDS";
> -			break;
> -		case AMDGPU_PL_GWS:
> -			placement = "GWS";
> -			break;
> -		case AMDGPU_PL_OA:
> -			placement = "OA";
> -			break;
> -		case AMDGPU_PL_PREEMPT:
> -			placement = "PREEMPTIBLE";
> -			break;
> -		case AMDGPU_PL_DOORBELL:
> -			placement = "DOORBELL";
> -			break;
> -		case TTM_PL_SYSTEM:
> -		default:
> -			placement = "CPU";
> -			break;
> +		if (!bo->tbo.resource) {
> +			placement = "NONE";
> +		} else {
> +			switch (bo->tbo.resource->mem_type) {
> +			case TTM_PL_VRAM:
> +				if (amdgpu_res_cpu_visible(adev, bo->tbo.resource))
> +					placement = "VRAM VISIBLE";
> +				else
> +					placement = "VRAM";
> +				break;
> +			case TTM_PL_TT:
> +				placement = "GTT";
> +				break;
> +			case AMDGPU_PL_GDS:
> +				placement = "GDS";
> +				break;
> +			case AMDGPU_PL_GWS:
> +				placement = "GWS";
> +				break;
> +			case AMDGPU_PL_OA:
> +				placement = "OA";
> +				break;
> +			case AMDGPU_PL_PREEMPT:
> +				placement = "PREEMPTIBLE";
> +				break;
> +			case AMDGPU_PL_DOORBELL:
> +				placement = "DOORBELL";
> +				break;
> +			case TTM_PL_SYSTEM:
> +			default:
> +				placement = "CPU";
> +				break;
> +			}
>   		}
>   		dma_resv_unlock(bo->tbo.base.resv);
>   	} else {



More information about the amd-gfx mailing list