Commit 6f57c933 authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA: Use u64_to_user_ptr everywhere

This is already used in many places, get the rest of them too, only
to make the code a bit clearer & simpler.
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 5b2cc79d
...@@ -430,7 +430,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file, ...@@ -430,7 +430,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
uevent->resp.id = ctx->id; uevent->resp.id = ctx->id;
} }
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&uevent->resp, sizeof(uevent->resp))) { &uevent->resp, sizeof(uevent->resp))) {
result = -EFAULT; result = -EFAULT;
goto done; goto done;
...@@ -441,7 +441,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file, ...@@ -441,7 +441,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
result = -ENOMEM; result = -ENOMEM;
goto done; goto done;
} }
if (copy_to_user((void __user *)(unsigned long)cmd.data, if (copy_to_user(u64_to_user_ptr(cmd.data),
uevent->data, uevent->data_len)) { uevent->data, uevent->data_len)) {
result = -EFAULT; result = -EFAULT;
goto done; goto done;
...@@ -453,7 +453,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file, ...@@ -453,7 +453,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
result = -ENOMEM; result = -ENOMEM;
goto done; goto done;
} }
if (copy_to_user((void __user *)(unsigned long)cmd.info, if (copy_to_user(u64_to_user_ptr(cmd.info),
uevent->info, uevent->info_len)) { uevent->info, uevent->info_len)) {
result = -EFAULT; result = -EFAULT;
goto done; goto done;
...@@ -502,7 +502,7 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file, ...@@ -502,7 +502,7 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
} }
resp.id = ctx->id; resp.id = ctx->id;
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) { &resp, sizeof(resp))) {
result = -EFAULT; result = -EFAULT;
goto err2; goto err2;
...@@ -556,7 +556,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file, ...@@ -556,7 +556,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
ib_ucm_cleanup_events(ctx); ib_ucm_cleanup_events(ctx);
resp.events_reported = ctx->events_reported; resp.events_reported = ctx->events_reported;
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) &resp, sizeof(resp)))
result = -EFAULT; result = -EFAULT;
...@@ -588,7 +588,7 @@ static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file, ...@@ -588,7 +588,7 @@ static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file,
resp.local_id = ctx->cm_id->local_id; resp.local_id = ctx->cm_id->local_id;
resp.remote_id = ctx->cm_id->remote_id; resp.remote_id = ctx->cm_id->remote_id;
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) &resp, sizeof(resp)))
result = -EFAULT; result = -EFAULT;
...@@ -625,7 +625,7 @@ static ssize_t ib_ucm_init_qp_attr(struct ib_ucm_file *file, ...@@ -625,7 +625,7 @@ static ssize_t ib_ucm_init_qp_attr(struct ib_ucm_file *file,
ib_copy_qp_attr_to_user(ctx->cm_id->device, &resp, &qp_attr); ib_copy_qp_attr_to_user(ctx->cm_id->device, &resp, &qp_attr);
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) &resp, sizeof(resp)))
result = -EFAULT; result = -EFAULT;
...@@ -699,7 +699,7 @@ static int ib_ucm_alloc_data(const void **dest, u64 src, u32 len) ...@@ -699,7 +699,7 @@ static int ib_ucm_alloc_data(const void **dest, u64 src, u32 len)
if (!len) if (!len)
return 0; return 0;
data = memdup_user((void __user *)(unsigned long)src, len); data = memdup_user(u64_to_user_ptr(src), len);
if (IS_ERR(data)) if (IS_ERR(data))
return PTR_ERR(data); return PTR_ERR(data);
...@@ -721,7 +721,7 @@ static int ib_ucm_path_get(struct sa_path_rec **path, u64 src) ...@@ -721,7 +721,7 @@ static int ib_ucm_path_get(struct sa_path_rec **path, u64 src)
if (!sa_path) if (!sa_path)
return -ENOMEM; return -ENOMEM;
if (copy_from_user(&upath, (void __user *)(unsigned long)src, if (copy_from_user(&upath, u64_to_user_ptr(src),
sizeof(upath))) { sizeof(upath))) {
kfree(sa_path); kfree(sa_path);
......
...@@ -420,7 +420,7 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf, ...@@ -420,7 +420,7 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
uevent->resp.id = ctx->id; uevent->resp.id = ctx->id;
} }
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&uevent->resp, &uevent->resp,
min_t(size_t, out_len, sizeof(uevent->resp)))) { min_t(size_t, out_len, sizeof(uevent->resp)))) {
ret = -EFAULT; ret = -EFAULT;
...@@ -489,7 +489,7 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf, ...@@ -489,7 +489,7 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
} }
resp.id = ctx->id; resp.id = ctx->id;
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) { &resp, sizeof(resp))) {
ret = -EFAULT; ret = -EFAULT;
goto err2; goto err2;
...@@ -614,7 +614,7 @@ static ssize_t ucma_destroy_id(struct ucma_file *file, const char __user *inbuf, ...@@ -614,7 +614,7 @@ static ssize_t ucma_destroy_id(struct ucma_file *file, const char __user *inbuf,
} }
resp.events_reported = ucma_free_ctx(ctx); resp.events_reported = ucma_free_ctx(ctx);
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) &resp, sizeof(resp)))
ret = -EFAULT; ret = -EFAULT;
...@@ -840,7 +840,7 @@ static ssize_t ucma_query_route(struct ucma_file *file, ...@@ -840,7 +840,7 @@ static ssize_t ucma_query_route(struct ucma_file *file,
ucma_copy_iw_route(&resp, &ctx->cm_id->route); ucma_copy_iw_route(&resp, &ctx->cm_id->route);
out: out:
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) &resp, sizeof(resp)))
ret = -EFAULT; ret = -EFAULT;
...@@ -986,7 +986,7 @@ static ssize_t ucma_query(struct ucma_file *file, ...@@ -986,7 +986,7 @@ static ssize_t ucma_query(struct ucma_file *file,
if (copy_from_user(&cmd, inbuf, sizeof(cmd))) if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
return -EFAULT; return -EFAULT;
response = (void __user *)(unsigned long) cmd.response; response = u64_to_user_ptr(cmd.response);
ctx = ucma_get_ctx(file, cmd.id); ctx = ucma_get_ctx(file, cmd.id);
if (IS_ERR(ctx)) if (IS_ERR(ctx))
return PTR_ERR(ctx); return PTR_ERR(ctx);
...@@ -1169,7 +1169,7 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file, ...@@ -1169,7 +1169,7 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file,
goto out; goto out;
ib_copy_qp_attr_to_user(ctx->cm_id->device, &resp, &qp_attr); ib_copy_qp_attr_to_user(ctx->cm_id->device, &resp, &qp_attr);
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) &resp, sizeof(resp)))
ret = -EFAULT; ret = -EFAULT;
...@@ -1305,7 +1305,7 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf, ...@@ -1305,7 +1305,7 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf,
if (unlikely(cmd.optval > KMALLOC_MAX_SIZE)) if (unlikely(cmd.optval > KMALLOC_MAX_SIZE))
return -EINVAL; return -EINVAL;
optval = memdup_user((void __user *) (unsigned long) cmd.optval, optval = memdup_user(u64_to_user_ptr(cmd.optval),
cmd.optlen); cmd.optlen);
if (IS_ERR(optval)) { if (IS_ERR(optval)) {
ret = PTR_ERR(optval); ret = PTR_ERR(optval);
...@@ -1383,7 +1383,7 @@ static ssize_t ucma_process_join(struct ucma_file *file, ...@@ -1383,7 +1383,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
goto err2; goto err2;
resp.id = mc->id; resp.id = mc->id;
if (copy_to_user((void __user *)(unsigned long) cmd->response, if (copy_to_user(u64_to_user_ptr(cmd->response),
&resp, sizeof(resp))) { &resp, sizeof(resp))) {
ret = -EFAULT; ret = -EFAULT;
goto err3; goto err3;
...@@ -1488,7 +1488,7 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file, ...@@ -1488,7 +1488,7 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file,
resp.events_reported = mc->events_reported; resp.events_reported = mc->events_reported;
kfree(mc); kfree(mc);
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) &resp, sizeof(resp)))
ret = -EFAULT; ret = -EFAULT;
out: out:
...@@ -1575,7 +1575,7 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file, ...@@ -1575,7 +1575,7 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
ucma_unlock_files(cur_file, new_file); ucma_unlock_files(cur_file, new_file);
response: response:
if (copy_to_user((void __user *)(unsigned long)cmd.response, if (copy_to_user(u64_to_user_ptr(cmd.response),
&resp, sizeof(resp))) &resp, sizeof(resp)))
ret = -EFAULT; ret = -EFAULT;
......
...@@ -3581,7 +3581,7 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, ...@@ -3581,7 +3581,7 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
if (cmd->srq_type == IB_SRQT_XRC) if (cmd->srq_type == IB_SRQT_XRC)
resp.srqn = srq->ext.xrc.srq_num; resp.srqn = srq->ext.xrc.srq_num;
if (copy_to_user((void __user *) (unsigned long) cmd->response, if (copy_to_user(u64_to_user_ptr(cmd->response),
&resp, sizeof resp)) { &resp, sizeof resp)) {
ret = -EFAULT; ret = -EFAULT;
goto err_copy; goto err_copy;
......
...@@ -473,7 +473,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, ...@@ -473,7 +473,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
tinfo->tidcnt = tididx; tinfo->tidcnt = tididx;
tinfo->length = mapped_pages * PAGE_SIZE; tinfo->length = mapped_pages * PAGE_SIZE;
if (copy_to_user((void __user *)(unsigned long)tinfo->tidlist, if (copy_to_user(u64_to_user_ptr(tinfo->tidlist),
tidlist, sizeof(tidlist[0]) * tididx)) { tidlist, sizeof(tidlist[0]) * tididx)) {
/* /*
* On failure to copy to the user level, we need to undo * On failure to copy to the user level, we need to undo
...@@ -513,7 +513,7 @@ int hfi1_user_exp_rcv_clear(struct hfi1_filedata *fd, ...@@ -513,7 +513,7 @@ int hfi1_user_exp_rcv_clear(struct hfi1_filedata *fd,
if (unlikely(tinfo->tidcnt > fd->tid_used)) if (unlikely(tinfo->tidcnt > fd->tid_used))
return -EINVAL; return -EINVAL;
tidinfo = memdup_user((void __user *)(unsigned long)tinfo->tidlist, tidinfo = memdup_user(u64_to_user_ptr(tinfo->tidlist),
sizeof(tidinfo[0]) * tinfo->tidcnt); sizeof(tidinfo[0]) * tinfo->tidcnt);
if (IS_ERR(tidinfo)) if (IS_ERR(tidinfo))
return PTR_ERR(tidinfo); return PTR_ERR(tidinfo);
......
...@@ -614,7 +614,7 @@ static ssize_t qib_diagpkt_write(struct file *fp, ...@@ -614,7 +614,7 @@ static ssize_t qib_diagpkt_write(struct file *fp,
} }
if (copy_from_user(tmpbuf, if (copy_from_user(tmpbuf,
(const void __user *) (unsigned long) dp.data, u64_to_user_ptr(dp.data),
dp.len)) { dp.len)) {
ret = -EFAULT; ret = -EFAULT;
goto bail; goto bail;
......
...@@ -443,7 +443,7 @@ static int qib_tid_update(struct qib_ctxtdata *rcd, struct file *fp, ...@@ -443,7 +443,7 @@ static int qib_tid_update(struct qib_ctxtdata *rcd, struct file *fp,
ret = -EFAULT; ret = -EFAULT;
goto cleanup; goto cleanup;
} }
if (copy_to_user((void __user *) (unsigned long) ti->tidmap, if (copy_to_user(u64_to_user_ptr(ti->tidmap),
tidmap, sizeof(tidmap))) { tidmap, sizeof(tidmap))) {
ret = -EFAULT; ret = -EFAULT;
goto cleanup; goto cleanup;
...@@ -490,7 +490,7 @@ static int qib_tid_free(struct qib_ctxtdata *rcd, unsigned subctxt, ...@@ -490,7 +490,7 @@ static int qib_tid_free(struct qib_ctxtdata *rcd, unsigned subctxt,
goto done; goto done;
} }
if (copy_from_user(tidmap, (void __user *)(unsigned long)ti->tidmap, if (copy_from_user(tidmap, u64_to_user_ptr(ti->tidmap),
sizeof(tidmap))) { sizeof(tidmap))) {
ret = -EFAULT; ret = -EFAULT;
goto done; goto done;
...@@ -2168,8 +2168,8 @@ static ssize_t qib_write(struct file *fp, const char __user *data, ...@@ -2168,8 +2168,8 @@ static ssize_t qib_write(struct file *fp, const char __user *data,
ret = qib_do_user_init(fp, &cmd.cmd.user_info); ret = qib_do_user_init(fp, &cmd.cmd.user_info);
if (ret) if (ret)
goto bail; goto bail;
ret = qib_get_base_info(fp, (void __user *) (unsigned long) ret = qib_get_base_info(fp, u64_to_user_ptr(
cmd.cmd.user_info.spu_base_info, cmd.cmd.user_info.spu_base_info),
cmd.cmd.user_info.spu_base_info_size); cmd.cmd.user_info.spu_base_info_size);
break; break;
......
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