mlx5: Return -EFAULT instead of -EPERM
For copy_to/from_user() failure, the correct error code is -EFAULT not -EPERM. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Roland Dreier <roland@purestorage.com>
This commit is contained in:
committed by
Roland Dreier
parent
288dde9f23
commit
5e631a03af
@@ -171,7 +171,7 @@ static ssize_t size_write(struct file *filp, const char __user *buf,
|
|||||||
int c;
|
int c;
|
||||||
|
|
||||||
if (copy_from_user(lbuf, buf, sizeof(lbuf)))
|
if (copy_from_user(lbuf, buf, sizeof(lbuf)))
|
||||||
return -EPERM;
|
return -EFAULT;
|
||||||
|
|
||||||
c = order2idx(dev, ent->order);
|
c = order2idx(dev, ent->order);
|
||||||
lbuf[sizeof(lbuf) - 1] = 0;
|
lbuf[sizeof(lbuf) - 1] = 0;
|
||||||
@@ -208,7 +208,7 @@ static ssize_t size_read(struct file *filp, char __user *buf, size_t count,
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (copy_to_user(buf, lbuf, err))
|
if (copy_to_user(buf, lbuf, err))
|
||||||
return -EPERM;
|
return -EFAULT;
|
||||||
|
|
||||||
*pos += err;
|
*pos += err;
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ static ssize_t limit_write(struct file *filp, const char __user *buf,
|
|||||||
int c;
|
int c;
|
||||||
|
|
||||||
if (copy_from_user(lbuf, buf, sizeof(lbuf)))
|
if (copy_from_user(lbuf, buf, sizeof(lbuf)))
|
||||||
return -EPERM;
|
return -EFAULT;
|
||||||
|
|
||||||
c = order2idx(dev, ent->order);
|
c = order2idx(dev, ent->order);
|
||||||
lbuf[sizeof(lbuf) - 1] = 0;
|
lbuf[sizeof(lbuf) - 1] = 0;
|
||||||
@@ -270,7 +270,7 @@ static ssize_t limit_read(struct file *filp, char __user *buf, size_t count,
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (copy_to_user(buf, lbuf, err))
|
if (copy_to_user(buf, lbuf, err))
|
||||||
return -EPERM;
|
return -EFAULT;
|
||||||
|
|
||||||
*pos += err;
|
*pos += err;
|
||||||
|
|
||||||
|
@@ -693,7 +693,7 @@ static ssize_t dbg_write(struct file *filp, const char __user *buf,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (copy_from_user(lbuf, buf, sizeof(lbuf)))
|
if (copy_from_user(lbuf, buf, sizeof(lbuf)))
|
||||||
return -EPERM;
|
return -EFAULT;
|
||||||
|
|
||||||
lbuf[sizeof(lbuf) - 1] = 0;
|
lbuf[sizeof(lbuf) - 1] = 0;
|
||||||
|
|
||||||
@@ -889,7 +889,7 @@ static ssize_t data_write(struct file *filp, const char __user *buf,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (copy_from_user(ptr, buf, count)) {
|
if (copy_from_user(ptr, buf, count)) {
|
||||||
err = -EPERM;
|
err = -EFAULT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
dbg->in_msg = ptr;
|
dbg->in_msg = ptr;
|
||||||
@@ -919,7 +919,7 @@ static ssize_t data_read(struct file *filp, char __user *buf, size_t count,
|
|||||||
|
|
||||||
copy = min_t(int, count, dbg->outlen);
|
copy = min_t(int, count, dbg->outlen);
|
||||||
if (copy_to_user(buf, dbg->out_msg, copy))
|
if (copy_to_user(buf, dbg->out_msg, copy))
|
||||||
return -EPERM;
|
return -EFAULT;
|
||||||
|
|
||||||
*pos += copy;
|
*pos += copy;
|
||||||
|
|
||||||
@@ -949,7 +949,7 @@ static ssize_t outlen_read(struct file *filp, char __user *buf, size_t count,
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (copy_to_user(buf, &outlen, err))
|
if (copy_to_user(buf, &outlen, err))
|
||||||
return -EPERM;
|
return -EFAULT;
|
||||||
|
|
||||||
*pos += err;
|
*pos += err;
|
||||||
|
|
||||||
@@ -974,7 +974,7 @@ static ssize_t outlen_write(struct file *filp, const char __user *buf,
|
|||||||
dbg->outlen = 0;
|
dbg->outlen = 0;
|
||||||
|
|
||||||
if (copy_from_user(outlen_str, buf, count))
|
if (copy_from_user(outlen_str, buf, count))
|
||||||
return -EPERM;
|
return -EFAULT;
|
||||||
|
|
||||||
outlen_str[7] = 0;
|
outlen_str[7] = 0;
|
||||||
|
|
||||||
|
@@ -148,7 +148,6 @@ static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
|
|||||||
struct mlx5_cmd_stats *stats;
|
struct mlx5_cmd_stats *stats;
|
||||||
u64 field = 0;
|
u64 field = 0;
|
||||||
int ret;
|
int ret;
|
||||||
int err;
|
|
||||||
char tbuf[22];
|
char tbuf[22];
|
||||||
|
|
||||||
if (*pos)
|
if (*pos)
|
||||||
@@ -161,9 +160,8 @@ static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
|
|||||||
spin_unlock(&stats->lock);
|
spin_unlock(&stats->lock);
|
||||||
ret = snprintf(tbuf, sizeof(tbuf), "%llu\n", field);
|
ret = snprintf(tbuf, sizeof(tbuf), "%llu\n", field);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
err = copy_to_user(buf, tbuf, ret);
|
if (copy_to_user(buf, tbuf, ret))
|
||||||
if (err)
|
return -EFAULT;
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*pos += ret;
|
*pos += ret;
|
||||||
@@ -418,7 +416,6 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
|
|||||||
char tbuf[18];
|
char tbuf[18];
|
||||||
u64 field;
|
u64 field;
|
||||||
int ret;
|
int ret;
|
||||||
int err;
|
|
||||||
|
|
||||||
if (*pos)
|
if (*pos)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -445,9 +442,8 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
|
|||||||
|
|
||||||
ret = snprintf(tbuf, sizeof(tbuf), "0x%llx\n", field);
|
ret = snprintf(tbuf, sizeof(tbuf), "0x%llx\n", field);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
err = copy_to_user(buf, tbuf, ret);
|
if (copy_to_user(buf, tbuf, ret))
|
||||||
if (err)
|
return -EFAULT;
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*pos += ret;
|
*pos += ret;
|
||||||
|
Reference in New Issue
Block a user