aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorErik Hugne <erik.hugne@ericsson.com>2012-06-29 00:50:22 -0400
committerPaul Gortmaker <paul.gortmaker@windriver.com>2012-07-13 19:28:28 -0400
commite2dbd601346aeb64b1b387168b217fd5c301644e (patch)
tree5386cec14012dc35b146b10a8309203f16f1474e /net/tipc
parent5deedde9fa65c494c9747dd66b1721be90991b64 (diff)
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>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/log.c52
1 files changed, 10 insertions, 42 deletions
diff --git a/net/tipc/log.c b/net/tipc/log.c
index 026733f24919..d01e37a61b93 100644
--- a/net/tipc/log.c
+++ b/net/tipc/log.c
@@ -71,21 +71,11 @@ struct print_buf *const TIPC_LOG = &log_buf;
71 * on the caller to prevent simultaneous use of the print buffer(s) being 71 * on the caller to prevent simultaneous use of the print buffer(s) being
72 * manipulated. 72 * manipulated.
73 */ 73 */
74static char print_string[TIPC_PB_MAX_STR];
75static DEFINE_SPINLOCK(print_lock); 74static DEFINE_SPINLOCK(print_lock);
76 75
77static void tipc_printbuf_move(struct print_buf *pb_to, 76static void tipc_printbuf_move(struct print_buf *pb_to,
78 struct print_buf *pb_from); 77 struct print_buf *pb_from);
79 78
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
89/** 79/**
90 * tipc_printbuf_init - initialize print buffer to empty 80 * tipc_printbuf_init - initialize print buffer to empty
91 * @pb: pointer to print buffer structure 81 * @pb: pointer to print buffer structure
@@ -220,39 +210,17 @@ static void tipc_printbuf_move(struct print_buf *pb_to,
220 */ 210 */
221void tipc_printf(struct print_buf *pb, const char *fmt, ...) 211void tipc_printf(struct print_buf *pb, const char *fmt, ...)
222{ 212{
223 int chars_to_add; 213 int i;
224 int chars_left; 214 va_list args;
225 char save_char; 215 char *buf;
226 216 int len;
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);
254 217
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;
256} 224}
257 225
258/** 226/**