mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
drm/amdgpu: Use memdup_array_user in amdgpu_cs_wait_fences_ioctl
Replace kmalloc_array() + copy_from_user() with memdup_array_user(). This shrinks the source code and improves separation between the kernel and userspace slabs. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
committed by
Alex Deucher
parent
c4ac100e9a
commit
dea75df7af
@@ -1767,30 +1767,21 @@ int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
|
|||||||
{
|
{
|
||||||
struct amdgpu_device *adev = drm_to_adev(dev);
|
struct amdgpu_device *adev = drm_to_adev(dev);
|
||||||
union drm_amdgpu_wait_fences *wait = data;
|
union drm_amdgpu_wait_fences *wait = data;
|
||||||
uint32_t fence_count = wait->in.fence_count;
|
|
||||||
struct drm_amdgpu_fence *fences_user;
|
|
||||||
struct drm_amdgpu_fence *fences;
|
struct drm_amdgpu_fence *fences;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
/* Get the fences from userspace */
|
/* Get the fences from userspace */
|
||||||
fences = kmalloc_array(fence_count, sizeof(struct drm_amdgpu_fence),
|
fences = memdup_array_user(u64_to_user_ptr(wait->in.fences),
|
||||||
GFP_KERNEL);
|
wait->in.fence_count,
|
||||||
if (fences == NULL)
|
sizeof(struct drm_amdgpu_fence));
|
||||||
return -ENOMEM;
|
if (IS_ERR(fences))
|
||||||
|
return PTR_ERR(fences);
|
||||||
fences_user = u64_to_user_ptr(wait->in.fences);
|
|
||||||
if (copy_from_user(fences, fences_user,
|
|
||||||
sizeof(struct drm_amdgpu_fence) * fence_count)) {
|
|
||||||
r = -EFAULT;
|
|
||||||
goto err_free_fences;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wait->in.wait_all)
|
if (wait->in.wait_all)
|
||||||
r = amdgpu_cs_wait_all_fences(adev, filp, wait, fences);
|
r = amdgpu_cs_wait_all_fences(adev, filp, wait, fences);
|
||||||
else
|
else
|
||||||
r = amdgpu_cs_wait_any_fence(adev, filp, wait, fences);
|
r = amdgpu_cs_wait_any_fence(adev, filp, wait, fences);
|
||||||
|
|
||||||
err_free_fences:
|
|
||||||
kfree(fences);
|
kfree(fences);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
Reference in New Issue
Block a user