git: 58d74d7b0ca9 - main - LinuxKPI: Use simple_read_from_buffer in simple_attr_read and seq_read
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Mar 2026 16:10:15 UTC
The branch main has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=58d74d7b0ca9bdf3aacfbe014bd00387f87b9be0
commit 58d74d7b0ca9bdf3aacfbe014bd00387f87b9be0
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2026-03-17 16:05:30 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2026-03-17 16:05:30 +0000
LinuxKPI: Use simple_read_from_buffer in simple_attr_read and seq_read
Reviewed by: bz
Sponsored by: AFRL, DARPA
Differential Revision: https://reviews.freebsd.org/D55879
---
sys/compat/linuxkpi/common/src/linux_seq_file.c | 11 ++---------
sys/compat/linuxkpi/common/src/linux_simple_attr.c | 13 ++-----------
2 files changed, 4 insertions(+), 20 deletions(-)
diff --git a/sys/compat/linuxkpi/common/src/linux_seq_file.c b/sys/compat/linuxkpi/common/src/linux_seq_file.c
index 6fe6ccd1e68e..b1d53aa2db60 100644
--- a/sys/compat/linuxkpi/common/src/linux_seq_file.c
+++ b/sys/compat/linuxkpi/common/src/linux_seq_file.c
@@ -60,15 +60,8 @@ seq_read(struct linux_file *f, char *ubuf, size_t size, off_t *ppos)
if (rc)
return (rc);
- rc = sbuf_len(sbuf);
- if (*ppos >= rc || size < 1)
- return (-EINVAL);
-
- size = min(rc - *ppos, size);
- memcpy(ubuf, sbuf_data(sbuf) + *ppos, size);
- *ppos += size;
-
- return (size);
+ return (simple_read_from_buffer(ubuf, size, ppos, sbuf_data(sbuf),
+ sbuf_len(sbuf)));
}
int
diff --git a/sys/compat/linuxkpi/common/src/linux_simple_attr.c b/sys/compat/linuxkpi/common/src/linux_simple_attr.c
index 8cc9ec7ecbc9..88fa908e47bb 100644
--- a/sys/compat/linuxkpi/common/src/linux_simple_attr.c
+++ b/sys/compat/linuxkpi/common/src/linux_simple_attr.c
@@ -119,18 +119,9 @@ simple_attr_read(struct file *filp, char *buf, size_t read_size, loff_t *ppos)
scnprintf(prebuf, sizeof(prebuf), sattr->fmt, data);
- ret = strlen(prebuf) + 1;
- if (*ppos >= ret || read_size < 1) {
- ret = -EINVAL;
- goto unlock;
- }
-
- read_size = min(ret - *ppos, read_size);
- ret = strscpy(buf, prebuf + *ppos, read_size);
-
/* add 1 for null terminator */
- if (ret > 0)
- ret += 1;
+ ret = simple_read_from_buffer(buf, read_size, ppos, prebuf,
+ strlen(prebuf) + 1);
unlock:
mutex_unlock(&sattr->mutex);