[PATCH linux dev-5.3 2/2] fsi: core: Fix small accesses and unaligned offsets via sysfs
Andrew Jeffery
andrew at aj.id.au
Thu Oct 31 16:14:38 AEDT 2019
Subtracting the offset delta from four-byte alignment lead to wrapping
of the requested length where `count` is less than `off`. Generalise the
length handling to enable all valid offset and size combinations.
Signed-off-by: Andrew Jeffery <andrew at aj.id.au>
Acked-by: Jeremy Kerr <jk at ozlabs.org>
---
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 1ea15621e588..889349beb284 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -559,8 +559,8 @@ static ssize_t fsi_slave_sysfs_raw_read(struct file *file,
return -EINVAL;
for (total_len = 0; total_len < count; total_len += read_len) {
- read_len = min_t(size_t, count, 4);
- read_len -= off & 0x3;
+ read_len = ((count | off) & 1) ?
+ 1 : min_t(size_t, count, 4 - (off & 3));
rc = fsi_slave_read(slave, off, buf + total_len, read_len);
if (rc)
@@ -587,8 +587,8 @@ static ssize_t fsi_slave_sysfs_raw_write(struct file *file,
return -EINVAL;
for (total_len = 0; total_len < count; total_len += write_len) {
- write_len = min_t(size_t, count, 4);
- write_len -= off & 0x3;
+ write_len = ((count | off) & 1) ?
+ 1 : min_t(size_t, count, 4 - (off & 3));
rc = fsi_slave_write(slave, off, buf + total_len, write_len);
if (rc)
--
2.20.1
More information about the openbmc
mailing list