diff mbox series

[36/74] backports: support strscpy_pad in older kernels

Message ID 20240524190907.1dee9821fe79.I57f107eb082c9a5d4ba9377bbf6c777013d7e24a@changeid (mailing list archive)
State New, archived
Headers show
Series backport updates from Intel | expand

Commit Message

Johannes Berg May 24, 2024, 5:07 p.m. UTC
From: Miri Korenblit <miriam.rachel.korenblit@intel.com>

This was added in kernel v5.2. Add support for it in older kernels.

Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 backport/backport-include/linux/string.h |  5 +++++
 backport/compat/backport-5.2.c           | 14 ++++++++++++++
 2 files changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/backport/backport-include/linux/string.h b/backport/backport-include/linux/string.h
index ce4c99e34e0d..f6e6cdcf08b8 100644
--- a/backport/backport-include/linux/string.h
+++ b/backport/backport-include/linux/string.h
@@ -23,4 +23,9 @@ 
 })
 #endif
 
+#if LINUX_VERSION_IS_LESS(5,2,0)
+#define strscpy_pad LINUX_BACKPORT(strscpy_pad)
+ssize_t strscpy_pad(char *dest, const char *src, size_t count);
+#endif
+
 #endif /* __BACKPORT_LINUX_STRING_H */
diff --git a/backport/compat/backport-5.2.c b/backport/compat/backport-5.2.c
index 5624d5fa08e5..581bb9cfe7fd 100644
--- a/backport/compat/backport-5.2.c
+++ b/backport/compat/backport-5.2.c
@@ -479,3 +479,17 @@  int __nla_parse(struct nlattr **tb, int maxtype,
 				    extack, tb);
 }
 EXPORT_SYMBOL(__nla_parse);
+
+ssize_t strscpy_pad(char *dest, const char *src, size_t count)
+{
+	ssize_t written;
+
+	written = strscpy(dest, src, count);
+	if (written < 0 || written == count - 1)
+		return written;
+
+	memset(dest + written + 1, 0, count - written - 1);
+
+	return written;
+}
+EXPORT_SYMBOL(strscpy_pad);