drm/amdgpu: avoid NULL pointer dereference
Subsystems (2)
PATCH 1/1 drm/amdgpu: avoid NULL pointer dereference
amdgpu_umc_poison_handler for UMC RAS consumption gets called in KFD queue reset, but it needs to return early when RAS context is NULL. This can guarantee lower access to RAS context like in amdgpu_umc_do_page_retirement. Also improve coding style in amdgpu_umc_poison_handler.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +8 -4
@@ -112,16 +112,20 @@ int amdgpu_umc_poison_handler(struct amdgpu_device *adev, void *ras_error_status, bool reset) { - int ret;struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;struct ras_common_if head = { .block =AMDGPU_RAS_BLOCK__UMC , }; -struct ras_manager *obj =amdgpu_ras_find_obj (adev, &head); +struct amdgpu_ras *con =amdgpu_ras_get_context (adev); +struct ras_manager *obj; +int ret; + +if (!con) +return 0 ; - ret = -amdgpu_umc_do_page_retirement (adev, ras_error_status,NULL , reset); + ret =amdgpu_umc_do_page_retirement (adev, ras_error_status,NULL , reset); + obj =amdgpu_ras_find_obj (adev, &head);if (ret ==AMDGPU_RAS_SUCCESS && obj) { obj->err_data.ue_count += err_data->ue_count; obj->err_data.ce_count += err_data->ce_count;
Signature · 1 line
2.17.1
[Public]
Hello Hawking,
Any comment to this patch?
Regards,
Guchun
-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: Wednesday, December 22, 2021 10:20 PM
To: [email protected]; Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Clements, John <[email protected]>; Lazar, Lijo <[email protected]>
Cc: Chen, Guchun <[email protected]>
Subject: [PATCH] drm/amdgpu: avoid NULL pointer dereference
amdgpu_umc_poison_handler for UMC RAS consumption gets called in KFD queue reset, but it needs to return early when RAS context is NULL. This can guarantee lower access to RAS context like in amdgpu_umc_do_page_retirement. Also improve coding style in amdgpu_umc_poison_handler.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +9 -4
@@ -112,16 +112,20 @@ int amdgpu_umc_poison_handler(struct amdgpu_device *adev, void *ras_error_status, bool reset) { - int ret;struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;struct ras_common_if head = { .block =AMDGPU_RAS_BLOCK__UMC , }; -struct ras_manager *obj =amdgpu_ras_find_obj (adev, &head); +struct amdgpu_ras *con =amdgpu_ras_get_context (adev); +struct ras_manager *obj; +int ret; + +if (!con) +return 0 ; - ret = -amdgpu_umc_do_page_retirement (adev, ras_error_status,NULL , reset); + ret =amdgpu_umc_do_page_retirement (adev, ras_error_status,NULL , +reset); + obj =amdgpu_ras_find_obj (adev, &head);if (ret ==AMDGPU_RAS_SUCCESS && obj) { obj->err_data.ue_count += err_data->ue_count;
obj->err_data.ce_count += err_data->ce_count;
--
2.17.1
LGTM Acked-by: Nirmoy Das <[email protected]>
Quoted 40 lines · Guchun Chen
amdgpu_umc_poison_handlerfor UMC RAS consumption gets called in KFD queue reset, but it needs to return early when RAS context is NULL. This can guarantee lower access to RAS context like inamdgpu_umc_do_page_retirement. Also improve coding style inamdgpu_umc_poison_handler.Signed-off-by Guchun Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +8
-4@@ -112,16 +112,20 @@ int amdgpu_umc_poison_handler(struct amdgpu_device *adev, void *ras_error_status, bool reset) { - int ret;struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;struct ras_common_if head = { .block =AMDGPU_RAS_BLOCK__UMC , }; -struct ras_manager *obj =amdgpu_ras_find_obj (adev, &head); +struct amdgpu_ras *con =amdgpu_ras_get_context (adev); +struct ras_manager *obj; +int ret; + +if (!con) +return 0 ; - ret = -amdgpu_umc_do_page_retirement (adev, ras_error_status,NULL , reset); + ret =amdgpu_umc_do_page_retirement (adev, ras_error_status,NULL , reset); + obj =amdgpu_ras_find_obj (adev, &head);if (ret ==AMDGPU_RAS_SUCCESS && obj) { obj->err_data.ue_count += err_data->ue_count; obj->err_data.ce_count += err_data->ce_count;