@@ -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;
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@codeconstruct.com.au> Fixes: d1dcd6782576 ("fsi: Add cfam char devices") Reported-by: Luo Likang <luolikang@nsfocus.com> --- drivers/fsi/fsi-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)