[PATCH 009/437] lib/string_helpers: split __parse_int_array() into a helper

Jens Axboe
2024-04-11T15:31:45Z

No functional changes, just in preparation for providing an iter based
version.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
lib/string_helpers.c | 44 +++++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 69ba49b853c7..77f942809556 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -138,29 +138,11 @@ int string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
}
EXPORT_SYMBOL(string_get_size);

-/**
- * parse_int_array_user - Split string into a sequence of integers
- * @from: The user space buffer to read from
- * @count: The maximum number of bytes to read
- * @array: Returned pointer to sequence of integers
- *
- * On success @array is allocated and initialized with a sequence of
- * integers extracted from the @from plus an additional element that
- * begins the sequence and specifies the integers count.
- *
- * Caller takes responsibility for freeing @array when it is no longer
- * needed.
- */
-int parse_int_array_user(const char __user *from, size_t count, int **array)
+static int __parse_int_array(char *buf, int **array)
{
int *ints, nints;
- char *buf;
int ret = 0;

- buf = memdup_user_nul(from, count);
- if (IS_ERR(buf))
- return PTR_ERR(buf);
-
get_options(buf, 0, &nints);
if (!nints) {
ret = -ENOENT;
@@ -180,6 +162,30 @@ int parse_int_array_user(const char __user *from, size_t count, int **array)
kfree(buf);
return ret;
}
+
+/**
+ * parse_int_array_user - Split string into a sequence of integers
+ * @from: The user space buffer to read from
+ * @count: The maximum number of bytes to read
+ * @array: Returned pointer to sequence of integers
+ *
+ * On success @array is allocated and initialized with a sequence of
+ * integers extracted from the @from plus an additional element that
+ * begins the sequence and specifies the integers count.
+ *
+ * Caller takes responsibility for freeing @array when it is no longer
+ * needed.
+ */
+int parse_int_array_user(const char __user *from, size_t count, int **array)
+{
+ char *buf;
+
+ buf = memdup_user_nul(from, count);
+ if (IS_ERR(buf))
+ return PTR_ERR(buf);
+
+ return __parse_int_array(buf, array);
+}
EXPORT_SYMBOL(parse_int_array_user);

static bool unescape_space(char **src, char **dst)
--
2.43.0