git: a6575008038b - stable/13 - linuxkpi: Add `sysfs_emit()`

From: Jean-Sébastien Pédron <dumbbell_at_FreeBSD.org>
Date: Thu, 16 Feb 2023 11:55:47 UTC
The branch stable/13 has been updated by dumbbell (ports committer):

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

commit a6575008038b7c70f8aaf0e8c18abdfe60e03852
Author:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2023-01-11 23:23:33 +0000
Commit:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2023-02-16 11:55:12 +0000

    linuxkpi: Add `sysfs_emit()`
    
    Reviewed by:    manu
    Approved by:    manu
    Differential Revision:  https://reviews.freebsd.org/D38086
    
    (cherry picked from commit 4fee6659c42c264e17dad7625f8663a45594d46b)
---
 sys/compat/linuxkpi/common/include/linux/sysfs.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/sysfs.h b/sys/compat/linuxkpi/common/include/linux/sysfs.h
index e6b8ad210f16..b9689a367c90 100644
--- a/sys/compat/linuxkpi/common/include/linux/sysfs.h
+++ b/sys/compat/linuxkpi/common/include/linux/sysfs.h
@@ -37,6 +37,7 @@
 
 #include <linux/kobject.h>
 #include <linux/stringify.h>
+#include <linux/mm.h>
 
 struct sysfs_ops {
 	ssize_t (*show)(struct kobject *, struct attribute *, char *);
@@ -295,6 +296,24 @@ sysfs_streq(const char *s1, const char *s2)
 	return (l1 == l2 && strncmp(s1, s2, l1) == 0);
 }
 
+static inline int
+sysfs_emit(char *buf, const char *fmt, ...)
+{
+	va_list args;
+	int i;
+
+	if (!buf || offset_in_page(buf)) {
+		pr_warn("invalid sysfs_emit: buf:%p\n", buf);
+		return (0);
+	}
+
+	va_start(args, fmt);
+	i = vscnprintf(buf, PAGE_SIZE, fmt, args);
+	va_end(args);
+
+	return (i);
+}
+
 #define sysfs_attr_init(attr) do {} while(0)
 
 #endif	/* _LINUXKPI_LINUX_SYSFS_H_ */