Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/string_helpers: Introduce parse_int_array()

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>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20250404090337.3564117-2-cezary.rojewski@intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Cezary Rojewski and committed by
Mark Brown
83b9ae77 0af2f6be

+22 -18
+1
include/linux/string_helpers.h
··· 31 31 int string_get_size(u64 size, u64 blk_size, const enum string_size_units units, 32 32 char *buf, int len); 33 33 34 + int parse_int_array(const char *buf, size_t count, int **array); 34 35 int parse_int_array_user(const char __user *from, size_t count, int **array); 35 36 36 37 #define UNESCAPE_SPACE BIT(0)
+21 -18
lib/string_helpers.c
··· 138 138 } 139 139 EXPORT_SYMBOL(string_get_size); 140 140 141 + int parse_int_array(const char *buf, size_t count, int **array) 142 + { 143 + int *ints, nints; 144 + 145 + get_options(buf, 0, &nints); 146 + if (!nints) 147 + return -ENOENT; 148 + 149 + ints = kcalloc(nints + 1, sizeof(*ints), GFP_KERNEL); 150 + if (!ints) 151 + return -ENOMEM; 152 + 153 + get_options(buf, nints + 1, ints); 154 + *array = ints; 155 + 156 + return 0; 157 + } 158 + EXPORT_SYMBOL(parse_int_array); 159 + 141 160 /** 142 161 * parse_int_array_user - Split string into a sequence of integers 143 162 * @from: The user space buffer to read from ··· 172 153 */ 173 154 int parse_int_array_user(const char __user *from, size_t count, int **array) 174 155 { 175 - int *ints, nints; 176 156 char *buf; 177 - int ret = 0; 157 + int ret; 178 158 179 159 buf = memdup_user_nul(from, count); 180 160 if (IS_ERR(buf)) 181 161 return PTR_ERR(buf); 182 162 183 - get_options(buf, 0, &nints); 184 - if (!nints) { 185 - ret = -ENOENT; 186 - goto free_buf; 187 - } 188 - 189 - ints = kcalloc(nints + 1, sizeof(*ints), GFP_KERNEL); 190 - if (!ints) { 191 - ret = -ENOMEM; 192 - goto free_buf; 193 - } 194 - 195 - get_options(buf, nints + 1, ints); 196 - *array = ints; 197 - 198 - free_buf: 163 + ret = parse_int_array(buf, count, array); 199 164 kfree(buf); 200 165 return ret; 201 166 }