git: e64afbc21572 - main - linuxkpi: Add `sysfs_emit_at()` in <linux/sysfs.h>

From: Jean-Sébastien Pédron <dumbbell_at_FreeBSD.org>
Date: Wed, 25 Jan 2023 22:15:12 UTC
The branch main has been updated by dumbbell (ports committer):

URL: https://cgit.FreeBSD.org/src/commit/?id=e64afbc21572984ca1249e01ff6b1cab39b679b9

commit e64afbc21572984ca1249e01ff6b1cab39b679b9
Author:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2023-01-20 19:23:17 +0000
Commit:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2023-01-25 21:56:56 +0000

    linuxkpi: Add `sysfs_emit_at()` in <linux/sysfs.h>
    
    Reviewed by:    manu
    Approved by:    manu
    Differential Revision:  https://reviews.freebsd.org/D38159
---
 sys/compat/linuxkpi/common/include/linux/sysfs.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/sysfs.h b/sys/compat/linuxkpi/common/include/linux/sysfs.h
index b9689a367c90..9d19dd50dbbc 100644
--- a/sys/compat/linuxkpi/common/include/linux/sysfs.h
+++ b/sys/compat/linuxkpi/common/include/linux/sysfs.h
@@ -314,6 +314,24 @@ sysfs_emit(char *buf, const char *fmt, ...)
 	return (i);
 }
 
+static inline int
+sysfs_emit_at(char *buf, int at, const char *fmt, ...)
+{
+	va_list args;
+	int i;
+
+	if (!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE) {
+		pr_warn("invalid sysfs_emit: buf:%p at:%d\n", buf, at);
+		return (0);
+	}
+
+	va_start(args, fmt);
+	i = vscnprintf(buf + at, PAGE_SIZE - at, fmt, args);
+	va_end(args);
+
+	return (i);
+}
+
 #define sysfs_attr_init(attr) do {} while(0)
 
 #endif	/* _LINUXKPI_LINUX_SYSFS_H_ */