Commit 261aeba8 authored by Geliang Tang's avatar Geliang Tang Committed by Daniel Vetter

drm/i915: use memdup_user_nul

Use memdup_user_nul() helper instead of open-coding to simplify the
code.
Signed-off-by: default avatarGeliang Tang <geliangtang@gmail.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/6baf3aa45d0b5e0fd016b508bac905ebf8443aac.1493779294.git.geliangtang@gmail.com
parent 6f38123e
...@@ -3702,16 +3702,10 @@ static ssize_t i915_displayport_test_active_write(struct file *file, ...@@ -3702,16 +3702,10 @@ static ssize_t i915_displayport_test_active_write(struct file *file,
if (len == 0) if (len == 0)
return 0; return 0;
input_buffer = kmalloc(len + 1, GFP_KERNEL); input_buffer = memdup_user_nul(ubuf, len);
if (!input_buffer) if (IS_ERR(input_buffer))
return -ENOMEM; return PTR_ERR(input_buffer);
if (copy_from_user(input_buffer, ubuf, len)) {
status = -EFAULT;
goto out;
}
input_buffer[len] = '\0';
DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len); DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
drm_connector_list_iter_begin(dev, &conn_iter); drm_connector_list_iter_begin(dev, &conn_iter);
...@@ -3737,7 +3731,6 @@ static ssize_t i915_displayport_test_active_write(struct file *file, ...@@ -3737,7 +3731,6 @@ static ssize_t i915_displayport_test_active_write(struct file *file,
} }
} }
drm_connector_list_iter_end(&conn_iter); drm_connector_list_iter_end(&conn_iter);
out:
kfree(input_buffer); kfree(input_buffer);
if (status < 0) if (status < 0)
return status; return status;
......
...@@ -853,19 +853,12 @@ static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf, ...@@ -853,19 +853,12 @@ static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
return -E2BIG; return -E2BIG;
} }
tmpbuf = kmalloc(len + 1, GFP_KERNEL); tmpbuf = memdup_user_nul(ubuf, len);
if (!tmpbuf) if (IS_ERR(tmpbuf))
return -ENOMEM; return PTR_ERR(tmpbuf);
if (copy_from_user(tmpbuf, ubuf, len)) {
ret = -EFAULT;
goto out;
}
tmpbuf[len] = '\0';
ret = display_crc_ctl_parse(dev_priv, tmpbuf, len); ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
out:
kfree(tmpbuf); kfree(tmpbuf);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment