[PATCH V2] drm/amdgpu: fix dereference null return value for the function amdgpu_vm_pt_parent

Christian König christian.koenig at amd.com
Thu May 23 09:07:27 UTC 2024


Am 23.05.24 um 10:07 schrieb Jesse Zhang:
> The pointer parent may be NULLed by the function amdgpu_vm_pt_parent.
> To make the code more robust, check the pointer parent.
>
> V2: When parent is NULL here we should
>   probably call BUG() instead. (Christian)
>
> Signed-off-by: Jesse Zhang <Jesse.Zhang at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> index 0763382d305a..6fac8440012e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> @@ -706,11 +706,17 @@ int amdgpu_vm_pde_update(struct amdgpu_vm_update_params *params,
>   			 struct amdgpu_vm_bo_base *entry)
>   {
>   	struct amdgpu_vm_bo_base *parent = amdgpu_vm_pt_parent(entry);
> -	struct amdgpu_bo *bo = parent->bo, *pbo;
> +	struct amdgpu_bo *bo, *pbo;
>   	struct amdgpu_vm *vm = params->vm;
>   	uint64_t pde, pt, flags;
>   	unsigned int level;
>   
> +	if (!parent) {
> +		BUG();
> +		return -EINVAL;
> +	}
> +	bo = parent->bo;
> +

Mhm, think more about it a BUG() isn't fully justified here.

Maybe make that:

if (WARN_ON(!parent))
     return -EINVAL;

Thanks,
Christian.

>   	for (level = 0, pbo = bo->parent; pbo; ++level)
>   		pbo = pbo->parent;
>   



More information about the amd-gfx mailing list