@@ -8,4 +8,18 @@
_name##_show, _name##_store)
#endif
+#if LINUX_VERSION_IS_LESS(5,10,0)
+#define sysfs_emit LINUX_BACKPORT(sysfs_emit)
+#ifdef CONFIG_SYSFS
+__printf(2, 3)
+int sysfs_emit(char *buf, const char *fmt, ...);
+#else /* CONFIG_SYSFS */
+__printf(2, 3)
+static inline int sysfs_emit(char *buf, const char *fmt, ...)
+{
+ return 0;
+}
+#endif /* CONFIG_SYSFS */
+#endif /* < 5.10 */
+
#endif /* __BACKPORT_LINUX_SYSFS_H */
@@ -3,6 +3,7 @@
#include <linux/export.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
+#include <linux/sysfs.h>
/**
* dev_fetch_sw_netstats - get per-cpu network device statistics
@@ -52,3 +53,29 @@ int netif_rx_any_context(struct sk_buff *skb)
return netif_rx_ni(skb);
}
EXPORT_SYMBOL(netif_rx_any_context);
+
+/**
+ * sysfs_emit - scnprintf equivalent, aware of PAGE_SIZE buffer.
+ * @buf: start of PAGE_SIZE buffer.
+ * @fmt: format
+ * @...: optional arguments to @format
+ *
+ *
+ * Returns number of characters written to @buf.
+ */
+int sysfs_emit(char *buf, const char *fmt, ...)
+{
+ va_list args;
+ int len;
+
+ if (WARN(!buf || offset_in_page(buf),
+ "invalid sysfs_emit: buf:%p\n", buf))
+ return 0;
+
+ va_start(args, fmt);
+ len = vscnprintf(buf, PAGE_SIZE, fmt, args);
+ va_end(args);
+
+ return len;
+}
+EXPORT_SYMBOL_GPL(sysfs_emit);
Add the sysfs_emit() function which was added in Linux upstream commit 2efc459d06f1 ("sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output") and is now used by drivers-base-devcoredump.c Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> --- backport/backport-include/linux/sysfs.h | 14 +++++++++++++ backport/compat/backport-5.10.c | 27 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+)