AMD General Series is: Reviewed-by: Alex Deucher <[email protected]> ________________________________ From: amd-gfx <[email protected]> on behalf of Shiwu Zhang <[email protected]> Sent: Wednesday, May 20, 2026 4:34 AM To: [email protected] <[email protected]> Subject: [PATCH 3/3] drm/amdgpu: fix duplicated buffer allocation for concurrent
In case of concurrent calling to the bin file writing, use the mutex to avoid allocating the temporary buffer more than once. Signed-off-by: Shiwu Zhang <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c index 576372ead63e..60a1d86ba9fe 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c @@ -4942,14 +4942,17 @@ static ssize_t amdgpu_psp_vbflash_write(struct file *filp, struct kobject *kobj, return -ENOMEM; } + mutex_lock(&adev->psp.mutex); + /* TODO Just allocate max for now and optimize to realloc later if needed */ if (!adev->psp.vbflash_tmp_buf) { adev->psp.vbflash_tmp_buf = kvmalloc(AMD_VBIOS_FILE_MAX_SIZE_B, GFP_KERNEL); - if (!adev->psp.vbflash_tmp_buf) + if (!adev->psp.vbflash_tmp_buf) { + mutex_unlock(&adev->psp.mutex); return -ENOMEM; + } } - mutex_lock(&adev->psp.mutex); memcpy(adev->psp.vbflash_tmp_buf + pos, buffer, count); adev->psp.vbflash_image_size += count; mutex_unlock(&adev->psp.mutex); -- 2.43.0
