Skip to content

Commit e2dbd60

Browse files
Erik HugnePaul Gortmaker
authored andcommitted
tipc: simplify print buffer handling in tipc_printf
tipc_printf was previously used both to construct debug traces and to append data to buffers that should be sent over netlink to the tipc-config application. A global print_buffer was used to format the string before it was copied to the actual output buffer. This could lead to concurrent access of the global print_buffer, which then had to be lock protected. This is simplified by changing tipc_printf to append data directly to the output buffer using vscnprintf. With the new implementation of tipc_printf, there is no longer any risk of concurrent access to the internal log buffer, so the lock (and the comments describing it) are no longer strictly necessary. However, there are still a few functions that do grab this lock before resizing/dumping the log buffer. We leave the lock, and these functions untouched since they will be removed with a subsequent commit that drops the deprecated log buffer handling code Signed-off-by: Erik Hugne <erik.hugne@ericsson.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
1 parent 5deedde commit e2dbd60

1 file changed

Lines changed: 10 additions & 42 deletions

File tree

‎net/tipc/log.c‎

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,11 @@ struct print_buf *const TIPC_LOG = &log_buf;
7171
* on the caller to prevent simultaneous use of the print buffer(s) being
7272
* manipulated.
7373
*/
74-
static char print_string[TIPC_PB_MAX_STR];
7574
static DEFINE_SPINLOCK(print_lock);
7675

7776
static void tipc_printbuf_move(struct print_buf *pb_to,
7877
struct print_buf *pb_from);
7978

80-
#define FORMAT(PTR, LEN, FMT) \
81-
{\
82-
va_list args;\
83-
va_start(args, FMT);\
84-
LEN = vsprintf(PTR, FMT, args);\
85-
va_end(args);\
86-
*(PTR + LEN) = '\0';\
87-
}
88-
8979
/**
9080
* tipc_printbuf_init - initialize print buffer to empty
9181
* @pb: pointer to print buffer structure
@@ -220,39 +210,17 @@ static void tipc_printbuf_move(struct print_buf *pb_to,
220210
*/
221211
void tipc_printf(struct print_buf *pb, const char *fmt, ...)
222212
{
223-
int chars_to_add;
224-
int chars_left;
225-
char save_char;
226-
227-
spin_lock_bh(&print_lock);
228-
229-
FORMAT(print_string, chars_to_add, fmt);
230-
if (chars_to_add >= TIPC_PB_MAX_STR)
231-
strcpy(print_string, "*** PRINT BUFFER STRING TOO LONG ***");
232-
233-
if (pb->buf) {
234-
chars_left = pb->buf + pb->size - pb->crs - 1;
235-
if (chars_to_add <= chars_left) {
236-
strcpy(pb->crs, print_string);
237-
pb->crs += chars_to_add;
238-
} else if (chars_to_add >= (pb->size - 1)) {
239-
strcpy(pb->buf, print_string + chars_to_add + 1
240-
- pb->size);
241-
pb->crs = pb->buf + pb->size - 1;
242-
} else {
243-
strcpy(pb->buf, print_string + chars_left);
244-
save_char = print_string[chars_left];
245-
print_string[chars_left] = 0;
246-
strcpy(pb->crs, print_string);
247-
print_string[chars_left] = save_char;
248-
pb->crs = pb->buf + chars_to_add - chars_left;
249-
}
250-
}
251-
252-
if (pb->echo)
253-
printk("%s", print_string);
213+
int i;
214+
va_list args;
215+
char *buf;
216+
int len;
254217

255-
spin_unlock_bh(&print_lock);
218+
buf = pb->crs;
219+
len = pb->buf + pb->size - pb->crs;
220+
va_start(args, fmt);
221+
i = vscnprintf(buf, len, fmt, args);
222+
va_end(args);
223+
pb->crs += i;
256224
}
257225

258226
/**

0 commit comments

Comments
 (0)