]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amdgpu: fix duplicated buffer allocation for concurrent
authorShiwu Zhang <shiwu.zhang@amd.com>
Wed, 13 May 2026 06:45:54 +0000 (14:45 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 3 Jun 2026 17:52:36 +0000 (13:52 -0400)
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 <shiwu.zhang@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c

index e3210ce1718372569cee638ce2550f95227d07e1..96e1b72b9e1c703e287aaca7f0c7bd4c1b479d6c 100644 (file)
@@ -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);