[PATCH 1/3] fsi: core: Fix incorrect variable usage in cfam_write & cfam_read

Jeremy Kerr jk at codeconstruct.com.au
Thu Jul 1 18:17:56 AEST 2021


Currently, when calculating the length of an individual CFAM read/write
operation, we use the total requested read/write length, rather than the
remaining length.

This change uses the remaining length instead.

Signed-off-by: Jeremy Kerr <jk at codeconstruct.com.au>
Fixes: d1dcd6782576 ("fsi: Add cfam char devices")
Reported-by: Luo Likang <luolikang at nsfocus.com>
---
 drivers/fsi/fsi-core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index 59ddc9fd5bca..92d6d9462e96 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -708,7 +708,7 @@ static ssize_t cfam_read(struct file *filep, char __user *buf, size_t count,
 	for (total_len = 0; total_len < count; total_len += read_len) {
 		__be32 data;
 
-		read_len = min_t(size_t, count, 4);
+		read_len = min_t(size_t, count - total_len, 4);
 		read_len -= off & 0x3;
 
 		rc = fsi_slave_read(slave, off, &data, read_len);
@@ -721,7 +721,7 @@ static ssize_t cfam_read(struct file *filep, char __user *buf, size_t count,
 		}
 		off += read_len;
 	}
-	rc = count;
+	rc = total_len;
  fail:
 	*offset = off;
 	return rc;
@@ -745,7 +745,7 @@ static ssize_t cfam_write(struct file *filep, const char __user *buf,
 	for (total_len = 0; total_len < count; total_len += write_len) {
 		__be32 data;
 
-		write_len = min_t(size_t, count, 4);
+		write_len = min_t(size_t, count - total_len, 4);
 		write_len -= off & 0x3;
 
 		rc = copy_from_user(&data, buf + total_len, write_len);
@@ -758,7 +758,7 @@ static ssize_t cfam_write(struct file *filep, const char __user *buf,
 			goto fail;
 		off += write_len;
 	}
-	rc = count;
+	rc = total_len;
  fail:
 	*offset = off;
 	return rc;
-- 
2.30.2



More information about the linux-fsi mailing list