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

parser: add unsigned int parser

Will be used by fs parsing options

Link: https://lore.kernel.org/r/20210129045242.10268-1-bingjingc@synology.com
Reviewed-by: Robbie Ko<robbieko@synology.com>
Reviewed-by: Chung-Chiang Cheng <cccheng@synology.com>
Signed-off-by: BingJing Chang <bingjingc@synology.com>
Signed-off-by: Jan Kara <jack@suse.cz>

authored by

BingJing Chang and committed by
Jan Kara
01531ac3 63c9e47a

+23
+1
include/linux/parser.h
··· 29 29 30 30 int match_token(char *, const match_table_t table, substring_t args[]); 31 31 int match_int(substring_t *, int *result); 32 + int match_uint(substring_t *s, unsigned int *result); 32 33 int match_u64(substring_t *, u64 *result); 33 34 int match_octal(substring_t *, int *result); 34 35 int match_hex(substring_t *, int *result);
+22
lib/parser.c
··· 188 188 } 189 189 EXPORT_SYMBOL(match_int); 190 190 191 + /* 192 + * match_uint - scan a decimal representation of an integer from a substring_t 193 + * @s: substring_t to be scanned 194 + * @result: resulting integer on success 195 + * 196 + * Description: Attempts to parse the &substring_t @s as a decimal integer. On 197 + * success, sets @result to the integer represented by the string and returns 0. 198 + * Returns -ENOMEM, -EINVAL, or -ERANGE on failure. 199 + */ 200 + int match_uint(substring_t *s, unsigned int *result) 201 + { 202 + int err = -ENOMEM; 203 + char *buf = match_strdup(s); 204 + 205 + if (buf) { 206 + err = kstrtouint(buf, 10, result); 207 + kfree(buf); 208 + } 209 + return err; 210 + } 211 + EXPORT_SYMBOL(match_uint); 212 + 191 213 /** 192 214 * match_u64: - scan a decimal representation of a u64 from 193 215 * a substring_t