aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2020-11-11 23:29:29 +0100
committerHauke Mehrtens <hauke@hauke-m.de>2020-12-05 21:24:57 +0100
commit77e0ad9a910656a305c95c7829e6343b0e291308 (patch)
tree6e66749489aebf81ee11e6137568a28a7d28c35b
parenta58d385ea88c1bea9b0e20fe7ee5da1880ac4493 (diff)
downloadbackports-77e0ad9a910656a305c95c7829e6343b0e291308.tar.gz
backports: Add 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>
-rw-r--r--backport/backport-include/linux/sysfs.h14
-rw-r--r--backport/compat/backport-5.10.c27
2 files changed, 41 insertions, 0 deletions
diff --git a/backport/backport-include/linux/sysfs.h b/backport/backport-include/linux/sysfs.h
index 0b71db54..ad8a8229 100644
--- a/backport/backport-include/linux/sysfs.h
+++ b/backport/backport-include/linux/sysfs.h
@@ -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 */
diff --git a/backport/compat/backport-5.10.c b/backport/compat/backport-5.10.c
index 141862da..c3a7b7d3 100644
--- a/backport/compat/backport-5.10.c
+++ b/backport/compat/backport-5.10.c
@@ -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);