Fix: Remove 'type' argument from access_ok() function (v5.0)
[lttng-modules.git] / probes / lttng-probe-user.c
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
7b8ea3a5
MD
3 * lttng-probe-user.c
4 *
5 * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7b8ea3a5
MD
6 */
7
8#include <linux/uaccess.h>
8d90c035 9#include <linux/module.h>
80bb2600 10#include <wrapper/uaccess.h>
156a3977 11#include <probes/lttng-probe-user.h>
7b8ea3a5
MD
12
13/*
14 * Calculate string length. Include final null terminating character if there is
15 * one, or ends at first fault. Disabling page faults ensures that we can safely
16 * call this from pretty much any context, including those where the caller
17 * holds mmap_sem, or any lock which nests in mmap_sem.
18 */
19long lttng_strlen_user_inatomic(const char *addr)
20{
21 long count = 0;
a824008c 22 mm_segment_t old_fs;
7b8ea3a5 23
a824008c
MD
24 if (!addr)
25 return 0;
26
27 old_fs = get_fs();
7b8ea3a5
MD
28 set_fs(KERNEL_DS);
29 pagefault_disable();
30 for (;;) {
31 char v;
2a8b83a1 32 unsigned long ret;
7b8ea3a5 33
80bb2600 34 if (unlikely(!lttng_access_ok(VERIFY_READ,
f127e61e
MD
35 (__force const char __user *) addr,
36 sizeof(v))))
37 break;
7b8ea3a5
MD
38 ret = __copy_from_user_inatomic(&v,
39 (__force const char __user *)(addr),
40 sizeof(v));
2a8b83a1 41 if (unlikely(ret > 0))
7b8ea3a5
MD
42 break;
43 count++;
44 if (unlikely(!v))
45 break;
46 addr++;
47 }
48 pagefault_enable();
49 set_fs(old_fs);
50 return count;
51}
f127e61e 52EXPORT_SYMBOL_GPL(lttng_strlen_user_inatomic);
This page took 0.033786 seconds and 4 git commands to generate.