Skip to contentSkip to conversation

soc: aspeed: xdma: Return -EFAULT if copy_from_user() fails

PATCH In review Dan Carpenter 2 participants 2 messages Sep 30, 2020

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

PATCH 1/1 soc: aspeed: xdma: Return -EFAULT if copy_from_user() fails

The copy_from_user() function returns the number of bytes remaining which we weren't able to copy. This should return -EFAULT to the user.

Fixes 86609baa4217 ("soc: aspeed: xdma: Add user interface")
---
 drivers/soc/aspeed/aspeed-xdma.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/soc/aspeed/aspeed-xdma.c +2 -3
index 91b51a3de8df..e6b4744bda64 100644
@@ -569,9 +569,8 @@ static ssize_t aspeed_xdma_write(struct file *file, const char __user *buf,
 	if (len != sizeof(op))
 		return -EINVAL;
 
-	rc = copy_from_user(&op, buf, len);
-	if (rc)
-		return rc;
+	if (copy_from_user(&op, buf, len))
+		return -EFAULT;
 
 	if (!op.len || op.len > client->size ||
 	    op.direction > ASPEED_XDMA_DIRECTION_UPSTREAM)
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Dan Carpenter

The copy_from_user() function returns the number of bytes remaining which we weren't able to copy. This should return -EFAULT to the user.

Thanks,

Quoted 23 lines
Fixes 86609baa4217 ("soc: aspeed: xdma: Add user interface")
---
  drivers/soc/aspeed/aspeed-xdma.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/soc/aspeed/aspeed-xdma.c +2 -3
index 91b51a3de8df..e6b4744bda64 100644
@@ -569,9 +569,8 @@ static ssize_t aspeed_xdma_write(struct file *file, const char __user *buf,
  	if (len != sizeof(op))
  		return -EINVAL;
 
-	rc = copy_from_user(&op, buf, len);
-	if (rc)
-		return rc;
+	if (copy_from_user(&op, buf, len))
+		return -EFAULT;
 
  	if (!op.len || op.len > client->size ||
  	    op.direction > ASPEED_XDMA_DIRECTION_UPSTREAM)