Fix: update writeback instrumentation for kernel 4.14
[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
28/* Excludes final \0. */
29#define LTTNG_MAX_UINT_CHAR 10
30
31static inline
32int __must_check lttng_kstrtouint_from_user(const char __user *ubuf,
33 size_t count, unsigned int base, unsigned int *res)
34{
35 unsigned int _res;
36 char kbuf[LTTNG_MAX_UINT_CHAR + 1], *endptr;
37
38 memset(kbuf, 0, sizeof(kbuf));
39 if (copy_from_user(kbuf, ubuf, min_t(size_t, LTTNG_MAX_UINT_CHAR, count)))
40 return -EFAULT;
41
42 _res = simple_strtoul(kbuf, &endptr, base);
43 if (!endptr)
44 return -EINVAL;
45
46 *res = _res;
47 return 0;
48}
49#else
50static inline
51int __must_check lttng_kstrtouint_from_user(const char __user *ubuf,
52 size_t count, unsigned int base, unsigned int *res)
53{
54 return kstrtouint_from_user(ubuf, count, base, res);
55}
56#endif
57
58#endif /* _LTTNG_WRAPPER_KSTRTOX_H */
This page took 0.025947 seconds and 4 git commands to generate.