[PATCH 2/2] drm/amdgpu: fix dereferencing null pointer warning in ring_test_ib()

Christian König christian.koenig at amd.com
Fri Jun 7 11:39:29 UTC 2024


Am 07.06.24 um 10:33 schrieb Bob Zhou:
> To avoid null pointer dereference, Check return value and
> conduct error handling.

That doesn't make much sense.

At this point the amdgpu_mes_ctx_get_offs_cpu_addr() shouldn't be able 
to return NULL in the first place.

Regards,
Christian.

>
> Signed-off-by: Bob Zhou <bob.zhou at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 ++
>   drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 ++
>   drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 4 ++++
>   drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 4 ++++
>   drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 4 ++++
>   drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 4 ++++
>   6 files changed, 20 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> index 2a510351dfce..f131f96a734c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> @@ -547,6 +547,8 @@ static int gfx_v11_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
>   
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, padding);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, padding);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = cpu_to_le32(0xCAFEDEAD);
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
> index 460bf33a22b1..b5719760abe2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
> @@ -322,6 +322,8 @@ static int gfx_v12_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
>   
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, padding);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, padding);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = cpu_to_le32(0xCAFEDEAD);
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);
> diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
> index b7d33d78bce0..56edac57d1e3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
> @@ -984,6 +984,8 @@ static int sdma_v5_0_ring_test_ring(struct amdgpu_ring *ring)
>   					 AMDGPU_MES_CTX_PADDING_OFFS);
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = tmp;
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);
> @@ -1067,6 +1069,8 @@ static int sdma_v5_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
>   					 AMDGPU_MES_CTX_PADDING_OFFS);
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = tmp;
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);
> diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
> index cc9e961f0078..3e5316a24c90 100644
> --- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
> +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
> @@ -824,6 +824,8 @@ static int sdma_v5_2_ring_test_ring(struct amdgpu_ring *ring)
>   					 AMDGPU_MES_CTX_PADDING_OFFS);
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = tmp;
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);
> @@ -907,6 +909,8 @@ static int sdma_v5_2_ring_test_ib(struct amdgpu_ring *ring, long timeout)
>   					 AMDGPU_MES_CTX_PADDING_OFFS);
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = tmp;
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);
> diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c
> index c833b6b8373b..c1d6ece57bd4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c
> @@ -846,6 +846,8 @@ static int sdma_v6_0_ring_test_ring(struct amdgpu_ring *ring)
>   					 AMDGPU_MES_CTX_PADDING_OFFS);
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = tmp;
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);
> @@ -929,6 +931,8 @@ static int sdma_v6_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
>   					 AMDGPU_MES_CTX_PADDING_OFFS);
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = tmp;
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);
> diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c
> index 96514fd77e35..2ea988e7e242 100644
> --- a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c
> @@ -859,6 +859,8 @@ static int sdma_v7_0_ring_test_ring(struct amdgpu_ring *ring)
>   					 AMDGPU_MES_CTX_PADDING_OFFS);
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = tmp;
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);
> @@ -942,6 +944,8 @@ static int sdma_v7_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
>   					 AMDGPU_MES_CTX_PADDING_OFFS);
>   		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
>   		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
> +		if (cpu_ptr == NULL)
> +			return -EINVAL;
>   		*cpu_ptr = tmp;
>   	} else {
>   		r = amdgpu_device_wb_get(adev, &index);



More information about the amd-gfx mailing list