public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [patch -next] mlx5_core: return -EFAULT if copy_to_user() fails
@ 2013-07-10 10:57 Dan Carpenter
  2013-07-10 11:37 ` Or Gerlitz
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2013-07-10 10:57 UTC (permalink / raw)
  To: Eli Cohen; +Cc: linux-rdma, kernel-janitors

This should return an error code instead of the number of bytes
remaining to be copied.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
index a550a8e..4273c06 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
@@ -148,7 +148,6 @@ static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
 	struct mlx5_cmd_stats *stats;
 	u64 field = 0;
 	int ret;
-	int err;
 	char tbuf[22];
 
 	if (*pos)
@@ -161,9 +160,8 @@ static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
 	spin_unlock(&stats->lock);
 	ret = snprintf(tbuf, sizeof(tbuf), "%llu\n", field);
 	if (ret > 0) {
-		err = copy_to_user(buf, tbuf, ret);
-		if (err)
-			return err;
+		if (copy_to_user(buf, tbuf, ret))
+			return -EFAULT;
 	}
 
 	*pos += ret;
@@ -418,7 +416,6 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
 	char tbuf[18];
 	u64 field;
 	int ret;
-	int err;
 
 	if (*pos)
 		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);
 	if (ret > 0) {
-		err = copy_to_user(buf, tbuf, ret);
-		if (err)
-			return err;
+		if (copy_to_user(buf, tbuf, ret))
+			return -EFAULT;
 	}
 
 	*pos += ret;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch -next] mlx5_core: return -EFAULT if copy_to_user() fails
  2013-07-10 10:57 [patch -next] mlx5_core: return -EFAULT if copy_to_user() fails Dan Carpenter
@ 2013-07-10 11:37 ` Or Gerlitz
  0 siblings, 0 replies; 2+ messages in thread
From: Or Gerlitz @ 2013-07-10 11:37 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Eli Cohen, linux-rdma, kernel-janitors, Jack Morgenstein,
	Moshe Lazer

On 10/07/2013 13:57, Dan Carpenter wrote:
> This should return an error code instead of the number of bytes
> remaining to be copied.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
> index a550a8e..4273c06 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
> @@ -148,7 +148,6 @@ static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
>   	struct mlx5_cmd_stats *stats;
>   	u64 field = 0;
>   	int ret;
> -	int err;
>   	char tbuf[22];
>   
>   	if (*pos)
> @@ -161,9 +160,8 @@ static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
>   	spin_unlock(&stats->lock);
>   	ret = snprintf(tbuf, sizeof(tbuf), "%llu\n", field);
>   	if (ret > 0) {
> -		err = copy_to_user(buf, tbuf, ret);
> -		if (err)
> -			return err;
> +		if (copy_to_user(buf, tbuf, ret))
> +			return -EFAULT;
>   	}
>   
>   	*pos += ret;
> @@ -418,7 +416,6 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
>   	char tbuf[18];
>   	u64 field;
>   	int ret;
> -	int err;
>   
>   	if (*pos)
>   		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);
>   	if (ret > 0) {
> -		err = copy_to_user(buf, tbuf, ret);
> -		if (err)
> -			return err;
> +		if (copy_to_user(buf, tbuf, ret))
> +			return -EFAULT;
>   	}
>   
>   	*pos += ret;
>

ditto here

Acked-by: Or Gerlitz <ogerlitz@mellanox.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-07-10 11:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-10 10:57 [patch -next] mlx5_core: return -EFAULT if copy_to_user() fails Dan Carpenter
2013-07-10 11:37 ` Or Gerlitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox