Commit a176c67d authored by Mikko Perttunen's avatar Mikko Perttunen Committed by Thierry Reding

drm/tegra: Use u64_to_user_ptr helper

Use the u64_to_user_ptr helper macro to cast IOCTL argument u64 values
to user pointers instead of writing out the cast manually. Also do
some other cleanup with user pointers to make them stand out more
and look cleaner.
Signed-off-by: default avatarMikko Perttunen <mperttunen@nvidia.com>
Reviewed-by: default avatarDmitry Osipenko <digetx@gmail.com>
Tested-by: default avatarDmitry Osipenko <digetx@gmail.com>
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
parent 45bd862c
...@@ -386,12 +386,10 @@ int tegra_drm_submit(struct tegra_drm_context *context, ...@@ -386,12 +386,10 @@ int tegra_drm_submit(struct tegra_drm_context *context,
unsigned int num_cmdbufs = args->num_cmdbufs; unsigned int num_cmdbufs = args->num_cmdbufs;
unsigned int num_relocs = args->num_relocs; unsigned int num_relocs = args->num_relocs;
unsigned int num_waitchks = args->num_waitchks; unsigned int num_waitchks = args->num_waitchks;
struct drm_tegra_cmdbuf __user *cmdbufs = struct drm_tegra_cmdbuf __user *user_cmdbufs;
(void __user *)(uintptr_t)args->cmdbufs; struct drm_tegra_reloc __user *user_relocs;
struct drm_tegra_reloc __user *relocs = struct drm_tegra_waitchk __user *user_waitchks;
(void __user *)(uintptr_t)args->relocs; struct drm_tegra_syncpt __user *user_syncpt;
struct drm_tegra_waitchk __user *waitchks =
(void __user *)(uintptr_t)args->waitchks;
struct drm_tegra_syncpt syncpt; struct drm_tegra_syncpt syncpt;
struct host1x *host1x = dev_get_drvdata(drm->dev->parent); struct host1x *host1x = dev_get_drvdata(drm->dev->parent);
struct drm_gem_object **refs; struct drm_gem_object **refs;
...@@ -400,6 +398,11 @@ int tegra_drm_submit(struct tegra_drm_context *context, ...@@ -400,6 +398,11 @@ int tegra_drm_submit(struct tegra_drm_context *context,
unsigned int num_refs; unsigned int num_refs;
int err; int err;
user_cmdbufs = u64_to_user_ptr(args->cmdbufs);
user_relocs = u64_to_user_ptr(args->relocs);
user_waitchks = u64_to_user_ptr(args->waitchks);
user_syncpt = u64_to_user_ptr(args->syncpts);
/* We don't yet support other than one syncpt_incr struct per submit */ /* We don't yet support other than one syncpt_incr struct per submit */
if (args->num_syncpts != 1) if (args->num_syncpts != 1)
return -EINVAL; return -EINVAL;
...@@ -440,7 +443,7 @@ int tegra_drm_submit(struct tegra_drm_context *context, ...@@ -440,7 +443,7 @@ int tegra_drm_submit(struct tegra_drm_context *context,
struct tegra_bo *obj; struct tegra_bo *obj;
u64 offset; u64 offset;
if (copy_from_user(&cmdbuf, cmdbufs, sizeof(cmdbuf))) { if (copy_from_user(&cmdbuf, user_cmdbufs, sizeof(cmdbuf))) {
err = -EFAULT; err = -EFAULT;
goto fail; goto fail;
} }
...@@ -476,7 +479,7 @@ int tegra_drm_submit(struct tegra_drm_context *context, ...@@ -476,7 +479,7 @@ int tegra_drm_submit(struct tegra_drm_context *context,
host1x_job_add_gather(job, bo, cmdbuf.words, cmdbuf.offset); host1x_job_add_gather(job, bo, cmdbuf.words, cmdbuf.offset);
num_cmdbufs--; num_cmdbufs--;
cmdbufs++; user_cmdbufs++;
} }
/* copy and resolve relocations from submit */ /* copy and resolve relocations from submit */
...@@ -485,7 +488,7 @@ int tegra_drm_submit(struct tegra_drm_context *context, ...@@ -485,7 +488,7 @@ int tegra_drm_submit(struct tegra_drm_context *context,
struct tegra_bo *obj; struct tegra_bo *obj;
err = host1x_reloc_copy_from_user(&job->relocarray[num_relocs], err = host1x_reloc_copy_from_user(&job->relocarray[num_relocs],
&relocs[num_relocs], drm, &user_relocs[num_relocs], drm,
file); file);
if (err < 0) if (err < 0)
goto fail; goto fail;
...@@ -519,9 +522,8 @@ int tegra_drm_submit(struct tegra_drm_context *context, ...@@ -519,9 +522,8 @@ int tegra_drm_submit(struct tegra_drm_context *context,
struct host1x_waitchk *wait = &job->waitchk[num_waitchks]; struct host1x_waitchk *wait = &job->waitchk[num_waitchks];
struct tegra_bo *obj; struct tegra_bo *obj;
err = host1x_waitchk_copy_from_user(wait, err = host1x_waitchk_copy_from_user(
&waitchks[num_waitchks], wait, &user_waitchks[num_waitchks], file);
file);
if (err < 0) if (err < 0)
goto fail; goto fail;
...@@ -539,8 +541,7 @@ int tegra_drm_submit(struct tegra_drm_context *context, ...@@ -539,8 +541,7 @@ int tegra_drm_submit(struct tegra_drm_context *context,
} }
} }
if (copy_from_user(&syncpt, (void __user *)(uintptr_t)args->syncpts, if (copy_from_user(&syncpt, user_syncpt, sizeof(syncpt))) {
sizeof(syncpt))) {
err = -EFAULT; err = -EFAULT;
goto fail; goto fail;
} }
......
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