Drop uuid.h wrapper
[lttng-modules.git] / wrapper / kstrtox.h
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
5a18f28d
MJ
3 * wrapper/kstrtox.h
4 *
5 * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
5a18f28d
MJ
6 */
7
9f36eaed
MJ
8#ifndef _LTTNG_WRAPPER_KSTRTOX_H
9#define _LTTNG_WRAPPER_KSTRTOX_H
10
5a18f28d
MJ
11#include <linux/version.h>
12
13#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0))
14
d21ec53c
MD
15#include <linux/uaccess.h>
16
5a18f28d
MJ
17/* Excludes final \0. */
18#define LTTNG_MAX_UINT_CHAR 10
19
20static inline
21int __must_check lttng_kstrtouint_from_user(const char __user *ubuf,
22 size_t count, unsigned int base, unsigned int *res)
23{
24 unsigned int _res;
25 char kbuf[LTTNG_MAX_UINT_CHAR + 1], *endptr;
26
27 memset(kbuf, 0, sizeof(kbuf));
28 if (copy_from_user(kbuf, ubuf, min_t(size_t, LTTNG_MAX_UINT_CHAR, count)))
29 return -EFAULT;
30
31 _res = simple_strtoul(kbuf, &endptr, base);
32 if (!endptr)
33 return -EINVAL;
34
35 *res = _res;
36 return 0;
37}
38#else
39static inline
40int __must_check lttng_kstrtouint_from_user(const char __user *ubuf,
41 size_t count, unsigned int base, unsigned int *res)
42{
43 return kstrtouint_from_user(ubuf, count, base, res);
44}
45#endif
46
47#endif /* _LTTNG_WRAPPER_KSTRTOX_H */
This page took 0.028673 seconds and 4 git commands to generate.