From: Shiwu Zhang Date: Wed, 13 May 2026 06:45:54 +0000 (+0800) Subject: drm/amdgpu: fix duplicated buffer allocation for concurrent X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2064610469c5f7f5d665034ddd4c4365dff65f58;p=thirdparty%2Flinux.git 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 Reviewed-by: Alex Deucher Signed-off-by: Alex Deucher --- diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c index e3210ce171837..96e1b72b9e1c7 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c @@ -4651,14 +4651,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);