From: Cezary Rojewski <cezary.rojewski@intel.com>
To: broonie@kernel.org
Cc: tiwai@suse.com, perex@perex.cz,
amadeuszx.slawinski@linux.intel.com, linux-sound@vger.kernel.org,
hdegoede@redhat.com, Cezary Rojewski <cezary.rojewski@intel.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH 1/8] lib/string_helpers: Introduce parse_int_array()
Date: Fri, 4 Apr 2025 11:03:30 +0200 [thread overview]
Message-ID: <20250404090337.3564117-2-cezary.rojewski@intel.com> (raw)
In-Reply-To: <20250404090337.3564117-1-cezary.rojewski@intel.com>
Existing parse_inte_array_user() works with __user buffers only.
Separate array parsing from __user bits so the functionality can be
utilized with kernel buffers too.
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
include/linux/string_helpers.h | 1 +
lib/string_helpers.c | 39 ++++++++++++++++++----------------
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index e93fbb5b0c01..3fb88a1e9898 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -31,6 +31,7 @@ enum string_size_units {
int string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
char *buf, int len);
+int parse_int_array(const char *buf, size_t count, int **array);
int parse_int_array_user(const char __user *from, size_t count, int **array);
#define UNESCAPE_SPACE BIT(0)
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 91fa37b5c510..ffb8ead6d4cd 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -138,6 +138,25 @@ int string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
}
EXPORT_SYMBOL(string_get_size);
+int parse_int_array(const char *buf, size_t count, int **array)
+{
+ int *ints, nints;
+
+ get_options(buf, 0, &nints);
+ if (!nints)
+ return -ENOENT;
+
+ ints = kcalloc(nints + 1, sizeof(*ints), GFP_KERNEL);
+ if (!ints)
+ return -ENOMEM;
+
+ get_options(buf, nints + 1, ints);
+ *array = ints;
+
+ return 0;
+}
+EXPORT_SYMBOL(parse_int_array);
+
/**
* parse_int_array_user - Split string into a sequence of integers
* @from: The user space buffer to read from
@@ -153,30 +172,14 @@ EXPORT_SYMBOL(string_get_size);
*/
int parse_int_array_user(const char __user *from, size_t count, int **array)
{
- int *ints, nints;
char *buf;
- int ret = 0;
+ int ret;
buf = memdup_user_nul(from, count);
if (IS_ERR(buf))
return PTR_ERR(buf);
- get_options(buf, 0, &nints);
- if (!nints) {
- ret = -ENOENT;
- goto free_buf;
- }
-
- ints = kcalloc(nints + 1, sizeof(*ints), GFP_KERNEL);
- if (!ints) {
- ret = -ENOMEM;
- goto free_buf;
- }
-
- get_options(buf, nints + 1, ints);
- *array = ints;
-
-free_buf:
+ ret = parse_int_array(buf, count, array);
kfree(buf);
return ret;
}
--
2.25.1
next prev parent reply other threads:[~2025-04-04 8:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 9:03 [PATCH 0/8] ASoC: Intel: avs: 16 channels support Cezary Rojewski
2025-04-04 9:03 ` Cezary Rojewski [this message]
2025-04-04 11:06 ` [PATCH 1/8] lib/string_helpers: Introduce parse_int_array() Andy Shevchenko
2025-04-04 11:06 ` Andy Shevchenko
2025-04-04 11:25 ` Cezary Rojewski
2025-04-04 9:03 ` [PATCH 2/8] ALSA: hda: Allow for 16 channels configuration Cezary Rojewski
2025-04-04 14:27 ` Mark Brown
2025-04-04 9:03 ` [PATCH 3/8] ASoC: Intel: avs: Rename AVS_CHANNELS_MAX define Cezary Rojewski
2025-04-04 9:03 ` [PATCH 4/8] ASoC: Intel: avs: Allow for 16 channels configuration Cezary Rojewski
2025-04-04 9:03 ` [PATCH 5/8] ASoC: Intel: avs: Allow to specify custom configurations with i2s_test Cezary Rojewski
2025-04-04 9:03 ` [PATCH 6/8] ASoC: Intel: avs: Assign unique ID to platform devices Cezary Rojewski
2025-04-04 9:03 ` [PATCH 7/8] ASoC: Intel: avs: Iterate over correct number of TDMs Cezary Rojewski
2025-04-04 9:03 ` [PATCH 8/8] ASoC: Intel: avs: Support 16 TDMs in dynamic assignment Cezary Rojewski
2025-04-08 12:49 ` [PATCH 0/8] ASoC: Intel: avs: 16 channels support Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250404090337.3564117-2-cezary.rojewski@intel.com \
--to=cezary.rojewski@intel.com \
--cc=amadeuszx.slawinski@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=broonie@kernel.org \
--cc=hdegoede@redhat.com \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox