[PATCH] fsi: i2cr-scom: Fix error code in read/write

Dan Carpenter dan.carpenter at linaro.org
Thu Sep 7 19:55:46 AEST 2023


The copy_to/from_user() functions return the number of bytes that they
were not able to copy but we want to return negative -EFAULT to the
user.

Fixes: c0b34bed0bbf ("fsi: Add I2C Responder SCOM driver")
Signed-off-by: Dan Carpenter <dan.carpenter at linaro.org>
---
 drivers/fsi/i2cr-scom.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c
index cb7e02213032..df1e1df40332 100644
--- a/drivers/fsi/i2cr-scom.c
+++ b/drivers/fsi/i2cr-scom.c
@@ -45,9 +45,8 @@ static ssize_t i2cr_scom_read(struct file *filep, char __user *buf, size_t len,
 	if (ret)
 		return ret;
 
-	ret = copy_to_user(buf, &data, len);
-	if (ret)
-		return ret;
+	if (copy_to_user(buf, &data, len))
+		return -EFAULT;
 
 	return len;
 }
@@ -62,9 +61,8 @@ static ssize_t i2cr_scom_write(struct file *filep, const char __user *buf, size_
 	if (len != sizeof(data))
 		return -EINVAL;
 
-	ret = copy_from_user(&data, buf, len);
-	if (ret)
-		return ret;
+	if (copy_from_user(&data, buf, len))
+		return -EFAULT;
 
 	ret = fsi_master_i2cr_write(scom->i2cr, (u32)*offset, data);
 	if (ret)
-- 
2.39.2



More information about the linux-fsi mailing list