lkml.org 
[lkml]   [2024]   [Apr]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 010/437] lib/string_helpers: add parse_int_array_iter()
Date
Works just like parse_int_array_user(), except it takes and iov_iter
instead of a ubuf + length.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
include/linux/string_helpers.h | 2 ++
lib/string_helpers.c | 19 +++++++++++++++++++
2 files changed, 21 insertions(+)

diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index e93fbb5b0c01..f38157114fc0 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -11,6 +11,7 @@
struct device;
struct file;
struct task_struct;
+struct iov_iter;

static inline bool string_is_terminated(const char *s, int len)
{
@@ -32,6 +33,7 @@ int string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
char *buf, int len);

int parse_int_array_user(const char __user *from, size_t count, int **array);
+int parse_int_array_iter(struct iov_iter *from, int **array);

#define UNESCAPE_SPACE BIT(0)
#define UNESCAPE_OCTAL BIT(1)
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 77f942809556..ced4f77dc5e8 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -188,6 +188,25 @@ int parse_int_array_user(const char __user *from, size_t count, int **array)
}
EXPORT_SYMBOL(parse_int_array_user);

+/**
+ * parse_int_array_iter - Split string into a sequence of integers
+ * @from: The iov_iter buffer to read from
+ * @array: Returned pointer to sequence of integers
+ *
+ * See @parse_int_array_user, this is just the iov_iter variant.
+ */
+int parse_int_array_iter(struct iov_iter *from, int **array)
+{
+ char *buf;
+
+ buf = iterdup_nul(from, iov_iter_count(from));
+ if (IS_ERR(buf))
+ return PTR_ERR(buf);
+
+ return __parse_int_array(buf, array);
+}
+EXPORT_SYMBOL(parse_int_array_iter);
+
static bool unescape_space(char **src, char **dst)
{
char *p = *dst, *q = *src;
--
2.43.0

\
 
 \ /
  Last update: 2024-05-27 16:35    [W:1.388 / U:0.344 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site