Commit 99eeb835 authored by Thorsten Blum's avatar Thorsten Blum Committed by Alex Deucher
Browse files

drm/amdgpu: Replace kzalloc + copy_from_user with memdup_user



Replace kzalloc() followed by copy_from_user() with memdup_user() to
improve and simplify ta_if_load_debugfs_write() and
ta_if_invoke_debugfs_write().

No functional changes intended.

Reviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@igalia.com>
Signed-off-by: default avatarThorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 6156c101
Loading
Loading
Loading
Loading
+6 −14
Original line number Diff line number Diff line
@@ -171,13 +171,9 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp, const char *buf, size_t

	copy_pos += sizeof(uint32_t);

	ta_bin = kzalloc(ta_bin_len, GFP_KERNEL);
	if (!ta_bin)
		return -ENOMEM;
	if (copy_from_user((void *)ta_bin, &buf[copy_pos], ta_bin_len)) {
		ret = -EFAULT;
		goto err_free_bin;
	}
	ta_bin = memdup_user(&buf[copy_pos], ta_bin_len);
	if (IS_ERR(ta_bin))
		return PTR_ERR(ta_bin);

	/* Set TA context and functions */
	set_ta_context_funcs(psp, ta_type, &context);
@@ -327,13 +323,9 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, size
		return -EFAULT;
	copy_pos += sizeof(uint32_t);

	shared_buf = kzalloc(shared_buf_len, GFP_KERNEL);
	if (!shared_buf)
		return -ENOMEM;
	if (copy_from_user((void *)shared_buf, &buf[copy_pos], shared_buf_len)) {
		ret = -EFAULT;
		goto err_free_shared_buf;
	}
	shared_buf = memdup_user(&buf[copy_pos], shared_buf_len);
	if (IS_ERR(shared_buf))
		return PTR_ERR(shared_buf);

	set_ta_context_funcs(psp, ta_type, &context);