Fix: add missing uaccess.h include from kstrtox.h wrapper
[lttng-modules.git] / wrapper / kstrtox.h
CommitLineData
5a18f28d
MJ
1#ifndef _LTTNG_WRAPPER_KSTRTOX_H
2#define _LTTNG_WRAPPER_KSTRTOX_H
3
4/*
5 * wrapper/kstrtox.h
6 *
7 * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; only
12 * version 2.1 of the License.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <linux/version.h>
25
26#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0))
27
d21ec53c
MD
28#include <linux/uaccess.h>
29
5a18f28d
MJ
30/* Excludes final \0. */
31#define LTTNG_MAX_UINT_CHAR 10
32
33static inline
34int __must_check lttng_kstrtouint_from_user(const char __user *ubuf,
35 size_t count, unsigned int base, unsigned int *res)
36{
37 unsigned int _res;
38 char kbuf[LTTNG_MAX_UINT_CHAR + 1], *endptr;
39
40 memset(kbuf, 0, sizeof(kbuf));
41 if (copy_from_user(kbuf, ubuf, min_t(size_t, LTTNG_MAX_UINT_CHAR, count)))
42 return -EFAULT;
43
44 _res = simple_strtoul(kbuf, &endptr, base);
45 if (!endptr)
46 return -EINVAL;
47
48 *res = _res;
49 return 0;
50}
51#else
52static inline
53int __must_check lttng_kstrtouint_from_user(const char __user *ubuf,
54 size_t count, unsigned int base, unsigned int *res)
55{
56 return kstrtouint_from_user(ubuf, count, base, res);
57}
58#endif
59
60#endif /* _LTTNG_WRAPPER_KSTRTOX_H */
This page took 0.027572 seconds and 4 git commands to generate.