Message ID | 20250404090337.3564117-2-cezary.rojewski@intel.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 83b9ae77f06607d19f7d3dcc6008742051137b27 |
Headers | show |
Series | ASoC: Intel: avs: 16 channels support | expand |
On Fri, Apr 04, 2025 at 11:03:30AM +0200, Cezary Rojewski wrote: > 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. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> But do we have a user for this? I believe we don't accept code without a user.
On Fri, Apr 04, 2025 at 02:06:11PM +0300, Andy Shevchenko wrote: > On Fri, Apr 04, 2025 at 11:03:30AM +0200, Cezary Rojewski wrote: > > 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. > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > But do we have a user for this? I believe we don't accept code without a user. Okay, this patch 1 out of 8... Next time Cc people at least to the cover letter where it will be visible.
On 2025-04-04 1:06 PM, Andy Shevchenko wrote: > On Fri, Apr 04, 2025 at 02:06:11PM +0300, Andy Shevchenko wrote: >> On Fri, Apr 04, 2025 at 11:03:30AM +0200, Cezary Rojewski wrote: >>> 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. >> >> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> >> >> But do we have a user for this? I believe we don't accept code without a user. > > Okay, this patch 1 out of 8... Next time Cc people at least to the cover letter > where it will be visible. > My apologies. The idea was to add the Cc: tag so you are always pinged when something happens to the string_helper change while simultaneously adding --cc=Andy when doing git send-email for the entire series. I did forget about the latter :(
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; }