Skip to contentSkip to conversation

mlx5_core: return -EFAULT if copy_to_user() fails

PATCH In review Dan Carpenter 2 participants 2 messages Jul 10, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlx5_core: return -EFAULT if copy_to_user() fails

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

drivers/net/ethernet/mellanox/mlx5/core/debugfs.c +4 -8
index a550a8e..4273c06 100644
@@ -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;
Acked-by on v1 1/1
#1 lore raw
Quoted 40 lines · Dan Carpenter

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

drivers/net/ethernet/mellanox/mlx5/core/debugfs.c +2 -5
index a550a8e..4273c06 100644
@@ -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,
 

drivers/net/ethernet/mellanox/mlx5/core/debugfs.c static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count, · line 449

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/debugfs.c +2 -3
  	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