drm/amd/ras: drop redundant memset in amdgpu_virt_ras_get_cper_records()
Subsystems (2)
PATCH 1/1 drm/amd/ras: drop redundant memset in amdgpu_virt_ras_get_cper_records()
kzalloc() returns zeroed memory, so the memset after the allocation is redundant.
No functional change.
--- drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c +0 -2
@@ -298,8 +298,6 @@ static int amdgpu_virt_ras_get_cper_records(struct ras_core_context *ras_core,return RAS_CMD__ERROR_GENERIC ; } -memset (out_buf,0 , req->buf_size); -for (i =0 ; i < req->cper_num; i++) { batch_id = req->cper_start_id + i;if (batch_id >= overview->last_batch_id)
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Medium] Missing buffer full check causes successful operations to fail when the buffer is perfectly filled. --
commit 24dbd1a80d649ce6f08f74e92eab2a4b85e073a8
Author: Sang-Heon Jeon <[email protected]>
drm/amd/ras: drop redundant memset in amdgpu_virt_ras_get_cper_records()
This commit drops a redundant memset() after kzalloc() since kzalloc() already returns zeroed memory.
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c static int amdgpu_virt_ras_get_cper_records(struct ras_core_context *ras_core, · line 303
Quoted 13 lines
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c +0
-2@@ -298,8 +298,6 @@ static int amdgpu_virt_ras_get_cper_records(struct ras_core_context *ras_core,return RAS_CMD__ERROR_GENERIC ; } -memset (out_buf,0 , req->buf_size); -for (i =0 ; i < req->cper_num; i++) { batch_id = req->cper_start_id + i;if (batch_id >= overview->last_batch_id)
[Severity: Medium]
This is a pre-existing issue, but while reviewing this function, I noticed a potential issue if the buffer gets perfectly filled.
Further down in amdgpu_virt_ras_get_cper_records(), we have this sequence:
if (count > 0) {
ret = ras_cper_generate_batch_cper(ras_core, batch_logs, count,
&out_buf[offset], req->buf_size - offset, &real_data_len);
if (ret)
break;
offset += real_data_len;
}If a previous iteration perfectly fills the buffer, offset will exactly equal req->buf_size.
On the next iteration, req->buf_size - offset will evaluate to 0.
ras_cper_generate_batch_cper() explicitly rejects a buffer length of 0 by returning -EINVAL.
Because the caller treats -EINVAL as a fatal error (the check
ret && (ret != -ENOMEM) evaluates to true), the function fails completely and discards the successfully retrieved records rather than returning them to the caller.
Could we add a check to break early if offset >= req->buf_size, similar to how it is mitigated in ras_cmd_get_cper_records() in core/cmd.c?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1