[PATCH master 2/3] include: import Linux string_is_terminated helper

Ahmad Fatoum a.fatoum at pengutronix.de
Fri Oct 20 00:23:15 PDT 2023


Some binary formats read by barebox feature null-terminated string.
Import the kernel's string_is_terminated() helper to verify such
strings before passing them to string API.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/linux/string_helpers.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 include/linux/string_helpers.h

diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
new file mode 100644
index 000000000000..5a8a469be7c0
--- /dev/null
+++ b/include/linux/string_helpers.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_STRING_HELPERS_H_
+#define _LINUX_STRING_HELPERS_H_
+
+#include <linux/string.h>
+#include <linux/types.h>
+
+static inline bool string_is_terminated(const char *s, int len)
+{
+	return memchr(s, '\0', len) ? true : false;
+}
+
+#endif
-- 
2.39.2




More information about the barebox mailing list