diff options
| author | John Baldwin <jhb@FreeBSD.org> | 2026-03-17 16:05:30 +0000 |
|---|---|---|
| committer | John Baldwin <jhb@FreeBSD.org> | 2026-03-17 16:05:30 +0000 |
| commit | 58d74d7b0ca9bdf3aacfbe014bd00387f87b9be0 (patch) | |
| tree | f1aabb8b7394a1ebd2d5140cae2be7845be2cc7e | |
| parent | c181c8f5ca707962359e636ca5aa536e60147eee (diff) | |
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
| -rw-r--r-- | sys/compat/linuxkpi/common/src/linux_seq_file.c | 11 | ||||
| -rw-r--r-- | 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); |
