]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/trace_seq.h
net: rtnetlink: validate IFLA_MTU attribute in rtnl_create_link()
[mirror_ubuntu-bionic-kernel.git] / include / linux / trace_seq.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
9504504c
SR
2#ifndef _LINUX_TRACE_SEQ_H
3#define _LINUX_TRACE_SEQ_H
4
3a161d99 5#include <linux/seq_buf.h>
6d723736 6
78be6914
WZ
7#include <asm/page.h>
8
9504504c
SR
9/*
10 * Trace sequences are used to allow a function to call several other functions
6d3f1e12 11 * to create a string of data to use (up to a max of PAGE_SIZE).
9504504c
SR
12 */
13
14struct trace_seq {
15 unsigned char buffer[PAGE_SIZE];
3a161d99 16 struct seq_buf seq;
d184b31c 17 int full;
9504504c
SR
18};
19
20static inline void
21trace_seq_init(struct trace_seq *s)
22{
3a161d99 23 seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
d184b31c 24 s->full = 0;
9504504c
SR
25}
26
5ac48378
SRRH
27/**
28 * trace_seq_used - amount of actual data written to buffer
29 * @s: trace sequence descriptor
30 *
31 * Returns the amount of data written to the buffer.
32 *
33 * IMPORTANT!
34 *
35 * Use this instead of @s->seq.len if you need to pass the amount
36 * of data from the buffer to another buffer (userspace, or what not).
37 * The @s->seq.len on overflow is bigger than the buffer size and
38 * using it can cause access to undefined memory.
39 */
40static inline int trace_seq_used(struct trace_seq *s)
41{
42 return seq_buf_used(&s->seq);
43}
44
7b039cb4
SRRH
45/**
46 * trace_seq_buffer_ptr - return pointer to next location in buffer
47 * @s: trace sequence descriptor
48 *
49 * Returns the pointer to the buffer where the next write to
50 * the buffer will happen. This is useful to save the location
51 * that is about to be written to and then return the result
52 * of that write.
53 */
54static inline unsigned char *
55trace_seq_buffer_ptr(struct trace_seq *s)
56{
5ac48378 57 return s->buffer + seq_buf_used(&s->seq);
7b039cb4
SRRH
58}
59
19a7fe20
SRRH
60/**
61 * trace_seq_has_overflowed - return true if the trace_seq took too much
62 * @s: trace sequence descriptor
63 *
64 * Returns true if too much data was added to the trace_seq and it is
65 * now full and will not take anymore.
66 */
67static inline bool trace_seq_has_overflowed(struct trace_seq *s)
68{
3a161d99 69 return s->full || seq_buf_has_overflowed(&s->seq);
19a7fe20
SRRH
70}
71
9504504c
SR
72/*
73 * Currently only defined when tracing is enabled.
74 */
75#ifdef CONFIG_TRACING
b9075fa9 76extern __printf(2, 3)
dba39448 77void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
b9075fa9 78extern __printf(2, 0)
dba39448
SRRH
79void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
80extern void
9504504c 81trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
a63ce5b3 82extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
36aabfff
SRRH
83extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
84 int cnt);
dba39448
SRRH
85extern void trace_seq_puts(struct trace_seq *s, const char *str);
86extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
87extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
88extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
36aabfff 89 unsigned int len);
38eff289 90extern int trace_seq_path(struct trace_seq *s, const struct path *path);
9504504c 91
dba39448 92extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
4449bf92
SRRH
93 int nmaskbits);
94
9504504c 95#else /* CONFIG_TRACING */
dba39448 96static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
9504504c 97{
9504504c 98}
dba39448 99static inline void
9504504c
SR
100trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
101{
9504504c
SR
102}
103
dba39448 104static inline void
4449bf92
SRRH
105trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
106 int nmaskbits)
107{
4449bf92
SRRH
108}
109
a63ce5b3 110static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
9504504c 111{
a63ce5b3 112 return 0;
9504504c 113}
36aabfff
SRRH
114static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
115 int cnt)
9504504c
SR
116{
117 return 0;
118}
dba39448 119static inline void trace_seq_puts(struct trace_seq *s, const char *str)
9504504c 120{
9504504c 121}
dba39448 122static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
9504504c 123{
9504504c 124}
dba39448 125static inline void
36aabfff 126trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
9504504c 127{
9504504c 128}
dba39448 129static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
36aabfff 130 unsigned int len)
9504504c 131{
9504504c 132}
38eff289 133static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
9504504c
SR
134{
135 return 0;
136}
137#endif /* CONFIG_TRACING */
138
139#endif /* _LINUX_TRACE_SEQ_H */