Skip to content

Commit dba3944

Browse files
committed
tracing: Remove return values of most trace_seq_*() functions
The trace_seq_printf() and friends are used to store strings into a buffer that can be passed around from function to function. If the trace_seq buffer fills up, it will not print any more. The return values were somewhat inconsistant and using trace_seq_has_overflowed() was a better way to know if the write to the trace_seq buffer succeeded or not. Now that all users have removed reading the return value of the printf() type functions, they can safely return void and keep future users of them from reading the inconsistent values as well. Link: http://lkml.kernel.org/r/20141114011411.992510720@goodmis.org Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 183742f commit dba3944

2 files changed

Lines changed: 38 additions & 83 deletions

File tree

‎include/linux/trace_seq.h‎

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,40 +57,37 @@ static inline bool trace_seq_has_overflowed(struct trace_seq *s)
5757
*/
5858
#ifdef CONFIG_TRACING
5959
extern __printf(2, 3)
60-
int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
60+
void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
6161
extern __printf(2, 0)
62-
int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
63-
extern int
62+
void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
63+
extern void
6464
trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
6565
extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
6666
extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
6767
int cnt);
68-
extern int trace_seq_puts(struct trace_seq *s, const char *str);
69-
extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
70-
extern int trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
71-
extern int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
68+
extern void trace_seq_puts(struct trace_seq *s, const char *str);
69+
extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
70+
extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
71+
extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
7272
unsigned int len);
7373
extern int trace_seq_path(struct trace_seq *s, const struct path *path);
7474

75-
extern int trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
75+
extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
7676
int nmaskbits);
7777

7878
#else /* CONFIG_TRACING */
79-
static inline int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
79+
static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
8080
{
81-
return 0;
8281
}
83-
static inline int
82+
static inline void
8483
trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
8584
{
86-
return 0;
8785
}
8886

89-
static inline int
87+
static inline void
9088
trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
9189
int nmaskbits)
9290
{
93-
return 0;
9491
}
9592

9693
static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
@@ -102,23 +99,19 @@ static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
10299
{
103100
return 0;
104101
}
105-
static inline int trace_seq_puts(struct trace_seq *s, const char *str)
102+
static inline void trace_seq_puts(struct trace_seq *s, const char *str)
106103
{
107-
return 0;
108104
}
109-
static inline int trace_seq_putc(struct trace_seq *s, unsigned char c)
105+
static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
110106
{
111-
return 0;
112107
}
113-
static inline int
108+
static inline void
114109
trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
115110
{
116-
return 0;
117111
}
118-
static inline int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
112+
static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
119113
unsigned int len)
120114
{
121-
return 0;
122115
}
123116
static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
124117
{

‎kernel/trace/trace_seq.c‎

Lines changed: 23 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,15 @@ int trace_print_seq(struct seq_file *m, struct trace_seq *s)
6969
* trace_seq_printf() is used to store strings into a special
7070
* buffer (@s). Then the output may be either used by
7171
* the sequencer or pulled into another buffer.
72-
*
73-
* Returns 1 if we successfully written all the contents to
74-
* the buffer.
75-
* Returns 0 if we the length to write is bigger than the
76-
* reserved buffer space. In this case, nothing gets written.
7772
*/
78-
int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
73+
void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
7974
{
8075
unsigned int len = TRACE_SEQ_BUF_LEFT(s);
8176
va_list ap;
8277
int ret;
8378

8479
if (s->full || !len)
85-
return 0;
80+
return;
8681

8782
va_start(ap, fmt);
8883
ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
@@ -91,12 +86,10 @@ int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
9186
/* If we can't write it all, don't bother writing anything */
9287
if (ret >= len) {
9388
s->full = 1;
94-
return 0;
89+
return;
9590
}
9691

9792
s->len += ret;
98-
99-
return 1;
10093
}
10194
EXPORT_SYMBOL_GPL(trace_seq_printf);
10295

@@ -107,25 +100,18 @@ EXPORT_SYMBOL_GPL(trace_seq_printf);
107100
* @nmaskbits: The number of bits that are valid in @maskp
108101
*
109102
* Writes a ASCII representation of a bitmask string into @s.
110-
*
111-
* Returns 1 if we successfully written all the contents to
112-
* the buffer.
113-
* Returns 0 if we the length to write is bigger than the
114-
* reserved buffer space. In this case, nothing gets written.
115103
*/
116-
int trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
104+
void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
117105
int nmaskbits)
118106
{
119107
unsigned int len = TRACE_SEQ_BUF_LEFT(s);
120108
int ret;
121109

122110
if (s->full || !len)
123-
return 0;
111+
return;
124112

125113
ret = bitmap_scnprintf(s->buffer + s->len, len, maskp, nmaskbits);
126114
s->len += ret;
127-
128-
return 1;
129115
}
130116
EXPORT_SYMBOL_GPL(trace_seq_bitmask);
131117

@@ -139,28 +125,24 @@ EXPORT_SYMBOL_GPL(trace_seq_bitmask);
139125
* trace_seq_printf is used to store strings into a special
140126
* buffer (@s). Then the output may be either used by
141127
* the sequencer or pulled into another buffer.
142-
*
143-
* Returns how much it wrote to the buffer.
144128
*/
145-
int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
129+
void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
146130
{
147131
unsigned int len = TRACE_SEQ_BUF_LEFT(s);
148132
int ret;
149133

150134
if (s->full || !len)
151-
return 0;
135+
return;
152136

153137
ret = vsnprintf(s->buffer + s->len, len, fmt, args);
154138

155139
/* If we can't write it all, don't bother writing anything */
156140
if (ret >= len) {
157141
s->full = 1;
158-
return 0;
142+
return;
159143
}
160144

161145
s->len += ret;
162-
163-
return len;
164146
}
165147
EXPORT_SYMBOL_GPL(trace_seq_vprintf);
166148

@@ -178,28 +160,24 @@ EXPORT_SYMBOL_GPL(trace_seq_vprintf);
178160
*
179161
* This function will take the format and the binary array and finish
180162
* the conversion into the ASCII string within the buffer.
181-
*
182-
* Returns how much it wrote to the buffer.
183163
*/
184-
int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
164+
void trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
185165
{
186166
unsigned int len = TRACE_SEQ_BUF_LEFT(s);
187167
int ret;
188168

189169
if (s->full || !len)
190-
return 0;
170+
return;
191171

192172
ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
193173

194174
/* If we can't write it all, don't bother writing anything */
195175
if (ret >= len) {
196176
s->full = 1;
197-
return 0;
177+
return;
198178
}
199179

200180
s->len += ret;
201-
202-
return len;
203181
}
204182
EXPORT_SYMBOL_GPL(trace_seq_bprintf);
205183

@@ -212,25 +190,21 @@ EXPORT_SYMBOL_GPL(trace_seq_bprintf);
212190
* copy to user routines. This function records a simple string
213191
* into a special buffer (@s) for later retrieval by a sequencer
214192
* or other mechanism.
215-
*
216-
* Returns how much it wrote to the buffer.
217193
*/
218-
int trace_seq_puts(struct trace_seq *s, const char *str)
194+
void trace_seq_puts(struct trace_seq *s, const char *str)
219195
{
220196
unsigned int len = strlen(str);
221197

222198
if (s->full)
223-
return 0;
199+
return;
224200

225201
if (len > TRACE_SEQ_BUF_LEFT(s)) {
226202
s->full = 1;
227-
return 0;
203+
return;
228204
}
229205

230206
memcpy(s->buffer + s->len, str, len);
231207
s->len += len;
232-
233-
return len;
234208
}
235209
EXPORT_SYMBOL_GPL(trace_seq_puts);
236210

@@ -243,22 +217,18 @@ EXPORT_SYMBOL_GPL(trace_seq_puts);
243217
* copy to user routines. This function records a simple charater
244218
* into a special buffer (@s) for later retrieval by a sequencer
245219
* or other mechanism.
246-
*
247-
* Returns how much it wrote to the buffer.
248220
*/
249-
int trace_seq_putc(struct trace_seq *s, unsigned char c)
221+
void trace_seq_putc(struct trace_seq *s, unsigned char c)
250222
{
251223
if (s->full)
252-
return 0;
224+
return;
253225

254226
if (TRACE_SEQ_BUF_LEFT(s) < 1) {
255227
s->full = 1;
256-
return 0;
228+
return;
257229
}
258230

259231
s->buffer[s->len++] = c;
260-
261-
return 1;
262232
}
263233
EXPORT_SYMBOL_GPL(trace_seq_putc);
264234

@@ -271,23 +241,19 @@ EXPORT_SYMBOL_GPL(trace_seq_putc);
271241
* There may be cases where raw memory needs to be written into the
272242
* buffer and a strcpy() would not work. Using this function allows
273243
* for such cases.
274-
*
275-
* Returns how much it wrote to the buffer.
276244
*/
277-
int trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
245+
void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
278246
{
279247
if (s->full)
280-
return 0;
248+
return;
281249

282250
if (len > TRACE_SEQ_BUF_LEFT(s)) {
283251
s->full = 1;
284-
return 0;
252+
return;
285253
}
286254

287255
memcpy(s->buffer + s->len, mem, len);
288256
s->len += len;
289-
290-
return len;
291257
}
292258
EXPORT_SYMBOL_GPL(trace_seq_putmem);
293259

@@ -303,20 +269,17 @@ EXPORT_SYMBOL_GPL(trace_seq_putmem);
303269
* This is similar to trace_seq_putmem() except instead of just copying the
304270
* raw memory into the buffer it writes its ASCII representation of it
305271
* in hex characters.
306-
*
307-
* Returns how much it wrote to the buffer.
308272
*/
309-
int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
273+
void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
310274
unsigned int len)
311275
{
312276
unsigned char hex[HEX_CHARS];
313277
const unsigned char *data = mem;
314278
unsigned int start_len;
315279
int i, j;
316-
int cnt = 0;
317280

318281
if (s->full)
319-
return 0;
282+
return;
320283

321284
while (len) {
322285
start_len = min(len, HEX_CHARS - 1);
@@ -335,9 +298,8 @@ int trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
335298
len -= j / 2;
336299
hex[j++] = ' ';
337300

338-
cnt += trace_seq_putmem(s, hex, j);
301+
trace_seq_putmem(s, hex, j);
339302
}
340-
return cnt;
341303
}
342304
EXPORT_SYMBOL_GPL(trace_seq_putmem_hex);
343305

0 commit comments

Comments
 (0)