Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Tvrtko Ursulin and committed by
Alex Deucher
dea75df7 c4ac100e

+5 -14
+5 -14
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
··· 1767 1767 { 1768 1768 struct amdgpu_device *adev = drm_to_adev(dev); 1769 1769 union drm_amdgpu_wait_fences *wait = data; 1770 - uint32_t fence_count = wait->in.fence_count; 1771 - struct drm_amdgpu_fence *fences_user; 1772 1770 struct drm_amdgpu_fence *fences; 1773 1771 int r; 1774 1772 1775 1773 /* Get the fences from userspace */ 1776 - fences = kmalloc_array(fence_count, sizeof(struct drm_amdgpu_fence), 1777 - GFP_KERNEL); 1778 - if (fences == NULL) 1779 - return -ENOMEM; 1780 - 1781 - fences_user = u64_to_user_ptr(wait->in.fences); 1782 - if (copy_from_user(fences, fences_user, 1783 - sizeof(struct drm_amdgpu_fence) * fence_count)) { 1784 - r = -EFAULT; 1785 - goto err_free_fences; 1786 - } 1774 + fences = memdup_array_user(u64_to_user_ptr(wait->in.fences), 1775 + wait->in.fence_count, 1776 + sizeof(struct drm_amdgpu_fence)); 1777 + if (IS_ERR(fences)) 1778 + return PTR_ERR(fences); 1787 1779 1788 1780 if (wait->in.wait_all) 1789 1781 r = amdgpu_cs_wait_all_fences(adev, filp, wait, fences); 1790 1782 else 1791 1783 r = amdgpu_cs_wait_any_fence(adev, filp, wait, fences); 1792 1784 1793 - err_free_fences: 1794 1785 kfree(fences); 1795 1786 1796 1787 return r;