233 /**
234 * kstrtoint - convert a string to an int
235 * @s: The start of the string. The string must be null-terminated, and may also
236 * include a single newline before its terminating null. The first character
237 * may also be a plus sign or a minus sign.
238 * @base: The number base to use. The maximum supported base is 16. If base is
239 * given as 0, then the base of the string is automatically detected with the
240 * conventional semantics - If it begins with 0x the number will be parsed as a
241 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
242 * parsed as an octal number. Otherwise it will be parsed as a decimal.
243 * @res: Where to write the result of the conversion on success.
244 *
245 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
246 * Used as a replacement for the obsolete simple_strtoull. Return code must
247 * be checked.
248 */
249 int kstrtoint(const char *s, unsigned int base, int *res)
250 {
251 long long tmp;
252 int rv;
253
254 rv = kstrtoll(s, base, &tmp);
255 if (rv < 0)
256 return rv;
257 if (tmp != (long long)(int)tmp)
258 return -ERANGE;
259 *res = tmp;
260 return 0;
261 }
262 EXPORT_SYMBOL(kstrtoint);
294 int kstrtou8(const char *s, unsigned int base, u8 *res)
295 {
296 unsigned long long tmp;
297 int rv;
298
299 rv = kstrtoull(s, base, &tmp);
300 if (rv < 0)
301 return rv;
302 if (tmp != (unsigned long long)(u8)tmp)
303 return -ERANGE;
304 *res = tmp;
305 return 0;
306 }