b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) // SPDX-License-Identifier: GPL-2.0
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 2) /*
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 3) * Convert integer string representation to an integer.
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 4) * If an integer doesn't fit into specified type, -E is returned.
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 5) *
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 6) * Integer starts with optional sign.
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 7) * kstrtou*() functions do not accept sign "-".
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 8) *
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 9) * Radix 0 means autodetection: leading "0x" implies radix 16,
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 10) * leading "0" implies radix 8, otherwise radix is 10.
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 11) * Autodetection hints work after optional sign, but not before.
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 12) *
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 13) * If -E is returned, result is not touched.
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 14) */
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 15) #include <linux/ctype.h>
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 16) #include <linux/errno.h>
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 17) #include <linux/kernel.h>
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 18) #include <linux/math64.h>
8bc3bcc93a2b4 (Paul Gortmaker 2011-11-16 21:29:17 -0500 19) #include <linux/export.h>
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 20) #include <linux/types.h>
7c0f6ba682b9c (Linus Torvalds 2016-12-24 11:46:01 -0800 21) #include <linux/uaccess.h>
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 22) #include "kstrtox.h"
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 23)
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 24) const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 25) {
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 26) if (*base == 0) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 27) if (s[0] == '0') {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 28) if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 29) *base = 16;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 30) else
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 31) *base = 8;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 32) } else
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 33) *base = 10;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 34) }
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 35) if (*base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 36) s += 2;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 37) return s;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 38) }
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 39)
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 40) /*
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 41) * Convert non-negative integer string representation in explicitly given radix
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 42) * to an integer. A maximum of max_chars characters will be converted.
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 43) *
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 44) * Return number of characters consumed maybe or-ed with overflow bit.
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 45) * If overflow occurs, result integer (incorrect) is still returned.
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 46) *
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 47) * Don't you dare use this function.
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 48) */
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 49) unsigned int _parse_integer_limit(const char *s, unsigned int base, unsigned long long *p,
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 50) size_t max_chars)
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 51) {
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 52) unsigned long long res;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 53) unsigned int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 54)
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 55) res = 0;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 56) rv = 0;
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 57) while (max_chars--) {
be5f3c7774a15 (Alexey Dobriyan 2017-07-10 15:51:41 -0700 58) unsigned int c = *s;
be5f3c7774a15 (Alexey Dobriyan 2017-07-10 15:51:41 -0700 59) unsigned int lc = c | 0x20; /* don't tolower() this line */
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 60) unsigned int val;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 61)
be5f3c7774a15 (Alexey Dobriyan 2017-07-10 15:51:41 -0700 62) if ('0' <= c && c <= '9')
be5f3c7774a15 (Alexey Dobriyan 2017-07-10 15:51:41 -0700 63) val = c - '0';
be5f3c7774a15 (Alexey Dobriyan 2017-07-10 15:51:41 -0700 64) else if ('a' <= lc && lc <= 'f')
be5f3c7774a15 (Alexey Dobriyan 2017-07-10 15:51:41 -0700 65) val = lc - 'a' + 10;
78be959e38567 (Alexey Dobriyan 2011-04-14 15:22:02 -0700 66) else
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 67) break;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 68)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 69) if (val >= base)
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 70) break;
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 71) /*
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 72) * Check for overflow only if we are within range of
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 73) * it in the max base we support (16)
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 74) */
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 75) if (unlikely(res & (~0ull << 60))) {
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 76) if (res > div_u64(ULLONG_MAX - val, base))
8cfd56d479042 (Alexey Dobriyan 2016-10-11 13:51:32 -0700 77) rv |= KSTRTOX_OVERFLOW;
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 78) }
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 79) res = res * base + val;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 80) rv++;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 81) s++;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 82) }
690d137f448d4 (David Howells 2012-02-09 15:48:20 +0000 83) *p = res;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 84) return rv;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 85) }
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 86)
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 87) unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p)
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 88) {
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 89) return _parse_integer_limit(s, base, p, INT_MAX);
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 90) }
69476379eb453 (Richard Fitzgerald 2021-05-14 17:12:04 +0100 91)
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 92) static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 93) {
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 94) unsigned long long _res;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 95) unsigned int rv;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 96)
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 97) s = _parse_integer_fixup_radix(s, &base);
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 98) rv = _parse_integer(s, base, &_res);
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 99) if (rv & KSTRTOX_OVERFLOW)
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 100) return -ERANGE;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 101) if (rv == 0)
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 102) return -EINVAL;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 103) s += rv;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 104) if (*s == '\n')
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 105) s++;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 106) if (*s)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 107) return -EINVAL;
1dff46d698748 (Alexey Dobriyan 2011-10-31 17:12:28 -0700 108) *res = _res;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 109) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 110) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 111)
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 112) /**
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 113) * kstrtoull - convert a string to an unsigned long long
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 114) * @s: The start of the string. The string must be null-terminated, and may also
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 115) * include a single newline before its terminating null. The first character
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 116) * may also be a plus sign, but not a minus sign.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 117) * @base: The number base to use. The maximum supported base is 16. If base is
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 118) * given as 0, then the base of the string is automatically detected with the
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 119) * conventional semantics - If it begins with 0x the number will be parsed as a
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 120) * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 121) * parsed as an octal number. Otherwise it will be parsed as a decimal.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 122) * @res: Where to write the result of the conversion on success.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 123) *
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 124) * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
ef0f2685336bb (Kars Mulder 2020-08-11 18:34:56 -0700 125) * Preferred over simple_strtoull(). Return code must be checked.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 126) */
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 127) int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 128) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 129) if (s[0] == '+')
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 130) s++;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 131) return _kstrtoull(s, base, res);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 132) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 133) EXPORT_SYMBOL(kstrtoull);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 134)
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 135) /**
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 136) * kstrtoll - convert a string to a long long
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 137) * @s: The start of the string. The string must be null-terminated, and may also
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 138) * include a single newline before its terminating null. The first character
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 139) * may also be a plus sign or a minus sign.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 140) * @base: The number base to use. The maximum supported base is 16. If base is
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 141) * given as 0, then the base of the string is automatically detected with the
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 142) * conventional semantics - If it begins with 0x the number will be parsed as a
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 143) * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 144) * parsed as an octal number. Otherwise it will be parsed as a decimal.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 145) * @res: Where to write the result of the conversion on success.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 146) *
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 147) * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
ef0f2685336bb (Kars Mulder 2020-08-11 18:34:56 -0700 148) * Preferred over simple_strtoll(). Return code must be checked.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 149) */
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 150) int kstrtoll(const char *s, unsigned int base, long long *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 151) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 152) unsigned long long tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 153) int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 154)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 155) if (s[0] == '-') {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 156) rv = _kstrtoull(s + 1, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 157) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 158) return rv;
2d2e4715a65ca (Alexey Dobriyan 2015-09-09 15:36:17 -0700 159) if ((long long)-tmp > 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 160) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 161) *res = -tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 162) } else {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 163) rv = kstrtoull(s, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 164) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 165) return rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 166) if ((long long)tmp < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 167) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 168) *res = tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 169) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 170) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 171) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 172) EXPORT_SYMBOL(kstrtoll);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 173)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 174) /* Internal, do not use. */
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 175) int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 176) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 177) unsigned long long tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 178) int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 179)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 180) rv = kstrtoull(s, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 181) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 182) return rv;
048e513d87611 (Alexey Dobriyan 2018-10-30 15:05:46 -0700 183) if (tmp != (unsigned long)tmp)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 184) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 185) *res = tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 186) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 187) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 188) EXPORT_SYMBOL(_kstrtoul);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 189)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 190) /* Internal, do not use. */
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 191) int _kstrtol(const char *s, unsigned int base, long *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 192) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 193) long long tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 194) int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 195)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 196) rv = kstrtoll(s, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 197) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 198) return rv;
048e513d87611 (Alexey Dobriyan 2018-10-30 15:05:46 -0700 199) if (tmp != (long)tmp)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 200) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 201) *res = tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 202) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 203) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 204) EXPORT_SYMBOL(_kstrtol);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 205)
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 206) /**
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 207) * kstrtouint - convert a string to an unsigned int
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 208) * @s: The start of the string. The string must be null-terminated, and may also
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 209) * include a single newline before its terminating null. The first character
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 210) * may also be a plus sign, but not a minus sign.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 211) * @base: The number base to use. The maximum supported base is 16. If base is
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 212) * given as 0, then the base of the string is automatically detected with the
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 213) * conventional semantics - If it begins with 0x the number will be parsed as a
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 214) * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 215) * parsed as an octal number. Otherwise it will be parsed as a decimal.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 216) * @res: Where to write the result of the conversion on success.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 217) *
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 218) * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
ef0f2685336bb (Kars Mulder 2020-08-11 18:34:56 -0700 219) * Preferred over simple_strtoul(). Return code must be checked.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 220) */
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 221) int kstrtouint(const char *s, unsigned int base, unsigned int *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 222) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 223) unsigned long long tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 224) int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 225)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 226) rv = kstrtoull(s, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 227) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 228) return rv;
048e513d87611 (Alexey Dobriyan 2018-10-30 15:05:46 -0700 229) if (tmp != (unsigned int)tmp)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 230) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 231) *res = tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 232) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 233) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 234) EXPORT_SYMBOL(kstrtouint);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 235)
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 236) /**
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 237) * kstrtoint - convert a string to an int
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 238) * @s: The start of the string. The string must be null-terminated, and may also
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 239) * include a single newline before its terminating null. The first character
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 240) * may also be a plus sign or a minus sign.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 241) * @base: The number base to use. The maximum supported base is 16. If base is
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 242) * given as 0, then the base of the string is automatically detected with the
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 243) * conventional semantics - If it begins with 0x the number will be parsed as a
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 244) * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 245) * parsed as an octal number. Otherwise it will be parsed as a decimal.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 246) * @res: Where to write the result of the conversion on success.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 247) *
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 248) * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
ef0f2685336bb (Kars Mulder 2020-08-11 18:34:56 -0700 249) * Preferred over simple_strtol(). Return code must be checked.
4c925d6031f71 (Eldad Zack 2012-12-17 16:03:04 -0800 250) */
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 251) int kstrtoint(const char *s, unsigned int base, int *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 252) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 253) long long tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 254) int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 255)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 256) rv = kstrtoll(s, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 257) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 258) return rv;
048e513d87611 (Alexey Dobriyan 2018-10-30 15:05:46 -0700 259) if (tmp != (int)tmp)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 260) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 261) *res = tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 262) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 263) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 264) EXPORT_SYMBOL(kstrtoint);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 265)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 266) int kstrtou16(const char *s, unsigned int base, u16 *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 267) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 268) unsigned long long tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 269) int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 270)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 271) rv = kstrtoull(s, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 272) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 273) return rv;
048e513d87611 (Alexey Dobriyan 2018-10-30 15:05:46 -0700 274) if (tmp != (u16)tmp)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 275) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 276) *res = tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 277) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 278) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 279) EXPORT_SYMBOL(kstrtou16);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 280)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 281) int kstrtos16(const char *s, unsigned int base, s16 *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 282) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 283) long long tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 284) int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 285)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 286) rv = kstrtoll(s, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 287) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 288) return rv;
048e513d87611 (Alexey Dobriyan 2018-10-30 15:05:46 -0700 289) if (tmp != (s16)tmp)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 290) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 291) *res = tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 292) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 293) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 294) EXPORT_SYMBOL(kstrtos16);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 295)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 296) int kstrtou8(const char *s, unsigned int base, u8 *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 297) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 298) unsigned long long tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 299) int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 300)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 301) rv = kstrtoull(s, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 302) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 303) return rv;
048e513d87611 (Alexey Dobriyan 2018-10-30 15:05:46 -0700 304) if (tmp != (u8)tmp)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 305) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 306) *res = tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 307) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 308) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 309) EXPORT_SYMBOL(kstrtou8);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 310)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 311) int kstrtos8(const char *s, unsigned int base, s8 *res)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 312) {
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 313) long long tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 314) int rv;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 315)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 316) rv = kstrtoll(s, base, &tmp);
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 317) if (rv < 0)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 318) return rv;
048e513d87611 (Alexey Dobriyan 2018-10-30 15:05:46 -0700 319) if (tmp != (s8)tmp)
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 320) return -ERANGE;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 321) *res = tmp;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 322) return 0;
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 323) }
33ee3b2e2eb9b (Alexey Dobriyan 2011-03-22 16:34:40 -0700 324) EXPORT_SYMBOL(kstrtos8);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 325)
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 326) /**
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 327) * kstrtobool - convert common user inputs into boolean values
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 328) * @s: input string
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 329) * @res: result
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 330) *
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 331) * This routine returns 0 iff the first character is one of 'Yy1Nn0', or
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 332) * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 333) * pointed to by res is updated upon finding a match.
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 334) */
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 335) int kstrtobool(const char *s, bool *res)
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 336) {
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 337) if (!s)
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 338) return -EINVAL;
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 339)
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 340) switch (s[0]) {
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 341) case 'y':
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 342) case 'Y':
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 343) case '1':
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 344) *res = true;
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 345) return 0;
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 346) case 'n':
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 347) case 'N':
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 348) case '0':
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 349) *res = false;
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 350) return 0;
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 351) case 'o':
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 352) case 'O':
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 353) switch (s[1]) {
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 354) case 'n':
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 355) case 'N':
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 356) *res = true;
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 357) return 0;
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 358) case 'f':
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 359) case 'F':
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 360) *res = false;
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 361) return 0;
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 362) default:
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 363) break;
a81a5a17d44b2 (Kees Cook 2016-03-17 14:22:57 -0700 364) }
36f9ff9e03de8 (Gustavo A. R. Silva 2020-11-19 07:11:44 -0600 365) break;
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 366) default:
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 367) break;
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 368) }
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 369)
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 370) return -EINVAL;
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 371) }
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 372) EXPORT_SYMBOL(kstrtobool);
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 373)
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 374) /*
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 375) * Since "base" would be a nonsense argument, this open-codes the
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 376) * _from_user helper instead of using the helper macro below.
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 377) */
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 378) int kstrtobool_from_user(const char __user *s, size_t count, bool *res)
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 379) {
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 380) /* Longest string needed to differentiate, newline, terminator */
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 381) char buf[4];
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 382)
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 383) count = min(count, sizeof(buf) - 1);
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 384) if (copy_from_user(buf, s, count))
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 385) return -EFAULT;
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 386) buf[count] = '\0';
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 387) return kstrtobool(buf, res);
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 388) }
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 389) EXPORT_SYMBOL(kstrtobool_from_user);
ef951599074ba (Kees Cook 2016-03-17 14:22:50 -0700 390)
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 391) #define kstrto_from_user(f, g, type) \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 392) int f(const char __user *s, size_t count, unsigned int base, type *res) \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 393) { \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 394) /* sign, base 2 representation, newline, terminator */ \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 395) char buf[1 + sizeof(type) * 8 + 1 + 1]; \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 396) \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 397) count = min(count, sizeof(buf) - 1); \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 398) if (copy_from_user(buf, s, count)) \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 399) return -EFAULT; \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 400) buf[count] = '\0'; \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 401) return g(buf, base, res); \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 402) } \
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 403) EXPORT_SYMBOL(f)
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 404)
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 405) kstrto_from_user(kstrtoull_from_user, kstrtoull, unsigned long long);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 406) kstrto_from_user(kstrtoll_from_user, kstrtoll, long long);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 407) kstrto_from_user(kstrtoul_from_user, kstrtoul, unsigned long);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 408) kstrto_from_user(kstrtol_from_user, kstrtol, long);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 409) kstrto_from_user(kstrtouint_from_user, kstrtouint, unsigned int);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 410) kstrto_from_user(kstrtoint_from_user, kstrtoint, int);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 411) kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 412) kstrto_from_user(kstrtos16_from_user, kstrtos16, s16);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 413) kstrto_from_user(kstrtou8_from_user, kstrtou8, u8);
c196e32a111b0 (Alexey Dobriyan 2011-05-24 17:13:31 -0700 414) kstrto_from_user(kstrtos8_from_user, kstrtos8, s8);