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>
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);