diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2015-09-15 06:35:25 -0400 |
---|---|---|
committer | Doug Ledford <dledford@redhat.com> | 2015-09-18 11:28:47 -0400 |
commit | e1df0068a24ba56673183cc3bd392d8bc301d423 (patch) | |
tree | e607044c89eee498d0718100f2b3dc528299f9aa | |
parent | aadfc3b2042d69a6b4b8d719d4221b988d7f31a5 (diff) |
IB/hfi1: fix copy_to/from_user() error handling
copy_to/from_user() returns the number of bytes which we were not able
to copy. It doesn't return an error code.
Also a couple places had a printk() on error and I removed that because
people can take advantage of it to fill /var/log/messages with spam.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r-- | drivers/staging/rdma/hfi1/diag.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/drivers/staging/rdma/hfi1/diag.c b/drivers/staging/rdma/hfi1/diag.c index 6777d6b659cf..ce01deea834c 100644 --- a/drivers/staging/rdma/hfi1/diag.c +++ b/drivers/staging/rdma/hfi1/diag.c | |||
@@ -1012,11 +1012,10 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) | |||
1012 | case HFI1_SNOOP_IOCSETLINKSTATE_EXTRA: | 1012 | case HFI1_SNOOP_IOCSETLINKSTATE_EXTRA: |
1013 | memset(&link_info, 0, sizeof(link_info)); | 1013 | memset(&link_info, 0, sizeof(link_info)); |
1014 | 1014 | ||
1015 | ret = copy_from_user(&link_info, | 1015 | if (copy_from_user(&link_info, |
1016 | (struct hfi1_link_info __user *)arg, | 1016 | (struct hfi1_link_info __user *)arg, |
1017 | sizeof(link_info)); | 1017 | sizeof(link_info))) |
1018 | if (ret) | 1018 | ret = -EFAULT; |
1019 | break; | ||
1020 | 1019 | ||
1021 | value = link_info.port_state; | 1020 | value = link_info.port_state; |
1022 | index = link_info.port_number; | 1021 | index = link_info.port_number; |
@@ -1080,9 +1079,10 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) | |||
1080 | case HFI1_SNOOP_IOCGETLINKSTATE_EXTRA: | 1079 | case HFI1_SNOOP_IOCGETLINKSTATE_EXTRA: |
1081 | if (cmd == HFI1_SNOOP_IOCGETLINKSTATE_EXTRA) { | 1080 | if (cmd == HFI1_SNOOP_IOCGETLINKSTATE_EXTRA) { |
1082 | memset(&link_info, 0, sizeof(link_info)); | 1081 | memset(&link_info, 0, sizeof(link_info)); |
1083 | ret = copy_from_user(&link_info, | 1082 | if (copy_from_user(&link_info, |
1084 | (struct hfi1_link_info __user *)arg, | 1083 | (struct hfi1_link_info __user *)arg, |
1085 | sizeof(link_info)); | 1084 | sizeof(link_info))) |
1085 | ret = -EFAULT; | ||
1086 | index = link_info.port_number; | 1086 | index = link_info.port_number; |
1087 | } else { | 1087 | } else { |
1088 | ret = __get_user(index, (int __user *) arg); | 1088 | ret = __get_user(index, (int __user *) arg); |
@@ -1114,9 +1114,10 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) | |||
1114 | ppd->link_speed_active; | 1114 | ppd->link_speed_active; |
1115 | link_info.link_width_active = | 1115 | link_info.link_width_active = |
1116 | ppd->link_width_active; | 1116 | ppd->link_width_active; |
1117 | ret = copy_to_user( | 1117 | if (copy_to_user( |
1118 | (struct hfi1_link_info __user *)arg, | 1118 | (struct hfi1_link_info __user *)arg, |
1119 | &link_info, sizeof(link_info)); | 1119 | &link_info, sizeof(link_info))) |
1120 | ret = -EFAULT; | ||
1120 | } else { | 1121 | } else { |
1121 | ret = __put_user(value, (int __user *)arg); | 1122 | ret = __put_user(value, (int __user *)arg); |
1122 | } | 1123 | } |
@@ -1142,10 +1143,9 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) | |||
1142 | snoop_dbg("Setting filter"); | 1143 | snoop_dbg("Setting filter"); |
1143 | /* just copy command structure */ | 1144 | /* just copy command structure */ |
1144 | argp = (unsigned long *)arg; | 1145 | argp = (unsigned long *)arg; |
1145 | ret = copy_from_user(&filter_cmd, (void __user *)argp, | 1146 | if (copy_from_user(&filter_cmd, (void __user *)argp, |
1146 | sizeof(filter_cmd)); | 1147 | sizeof(filter_cmd))) { |
1147 | if (ret < 0) { | 1148 | ret = -EFAULT; |
1148 | pr_alert("Error copying filter command\n"); | ||
1149 | break; | 1149 | break; |
1150 | } | 1150 | } |
1151 | if (filter_cmd.opcode >= HFI1_MAX_FILTERS) { | 1151 | if (filter_cmd.opcode >= HFI1_MAX_FILTERS) { |
@@ -1167,12 +1167,11 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) | |||
1167 | break; | 1167 | break; |
1168 | } | 1168 | } |
1169 | /* copy remaining data from userspace */ | 1169 | /* copy remaining data from userspace */ |
1170 | ret = copy_from_user((u8 *)filter_value, | 1170 | if (copy_from_user((u8 *)filter_value, |
1171 | (void __user *)filter_cmd.value_ptr, | 1171 | (void __user *)filter_cmd.value_ptr, |
1172 | filter_cmd.length); | 1172 | filter_cmd.length)) { |
1173 | if (ret < 0) { | ||
1174 | kfree(filter_value); | 1173 | kfree(filter_value); |
1175 | pr_alert("Error copying filter data\n"); | 1174 | ret = -EFAULT; |
1176 | break; | 1175 | break; |
1177 | } | 1176 | } |
1178 | /* Drain packets first */ | 1177 | /* Drain packets first */ |