tipc: phase out most of the struct print_buf usage
[cascardo/linux.git] / net / tipc / log.c
index 026733f..fa7ce92 100644 (file)
@@ -71,21 +71,11 @@ struct print_buf *const TIPC_LOG = &log_buf;
  * on the caller to prevent simultaneous use of the print buffer(s) being
  * manipulated.
  */
-static char print_string[TIPC_PB_MAX_STR];
 static DEFINE_SPINLOCK(print_lock);
 
 static void tipc_printbuf_move(struct print_buf *pb_to,
                               struct print_buf *pb_from);
 
-#define FORMAT(PTR, LEN, FMT) \
-{\
-       va_list args;\
-       va_start(args, FMT);\
-       LEN = vsprintf(PTR, FMT, args);\
-       va_end(args);\
-       *(PTR + LEN) = '\0';\
-}
-
 /**
  * tipc_printbuf_init - initialize print buffer to empty
  * @pb: pointer to print buffer structure
@@ -134,40 +124,6 @@ static int tipc_printbuf_empty(struct print_buf *pb)
        return !pb->buf || (pb->crs == pb->buf);
 }
 
-/**
- * tipc_printbuf_validate - check for print buffer overflow
- * @pb: pointer to print buffer structure
- *
- * Verifies that a print buffer has captured all data written to it.
- * If data has been lost, linearize buffer and prepend an error message
- *
- * Returns length of print buffer data string (including trailing NUL)
- */
-int tipc_printbuf_validate(struct print_buf *pb)
-{
-       char *err = "\n\n*** PRINT BUFFER OVERFLOW ***\n\n";
-       char *cp_buf;
-       struct print_buf cb;
-
-       if (!pb->buf)
-               return 0;
-
-       if (pb->buf[pb->size - 1] == 0) {
-               cp_buf = kmalloc(pb->size, GFP_ATOMIC);
-               if (cp_buf) {
-                       tipc_printbuf_init(&cb, cp_buf, pb->size);
-                       tipc_printbuf_move(&cb, pb);
-                       tipc_printbuf_move(pb, &cb);
-                       kfree(cp_buf);
-                       memcpy(pb->buf, err, strlen(err));
-               } else {
-                       tipc_printbuf_reset(pb);
-                       tipc_printf(pb, err);
-               }
-       }
-       return pb->crs - pb->buf + 1;
-}
-
 /**
  * tipc_printbuf_move - move print buffer contents to another print buffer
  * @pb_to: pointer to destination print buffer structure
@@ -214,45 +170,20 @@ static void tipc_printbuf_move(struct print_buf *pb_to,
 }
 
 /**
- * tipc_printf - append formatted output to print buffer
- * @pb: pointer to print buffer
+ * tipc_snprintf - append formatted output to print buffer
+ * @buf: pointer to print buffer
+ * @len: buffer length
  * @fmt: formatted info to be printed
  */
-void tipc_printf(struct print_buf *pb, const char *fmt, ...)
+int tipc_snprintf(char *buf, int len, const char *fmt, ...)
 {
-       int chars_to_add;
-       int chars_left;
-       char save_char;
-
-       spin_lock_bh(&print_lock);
-
-       FORMAT(print_string, chars_to_add, fmt);
-       if (chars_to_add >= TIPC_PB_MAX_STR)
-               strcpy(print_string, "*** PRINT BUFFER STRING TOO LONG ***");
+       int i;
+       va_list args;
 
-       if (pb->buf) {
-               chars_left = pb->buf + pb->size - pb->crs - 1;
-               if (chars_to_add <= chars_left) {
-                       strcpy(pb->crs, print_string);
-                       pb->crs += chars_to_add;
-               } else if (chars_to_add >= (pb->size - 1)) {
-                       strcpy(pb->buf, print_string + chars_to_add + 1
-                              - pb->size);
-                       pb->crs = pb->buf + pb->size - 1;
-               } else {
-                       strcpy(pb->buf, print_string + chars_left);
-                       save_char = print_string[chars_left];
-                       print_string[chars_left] = 0;
-                       strcpy(pb->crs, print_string);
-                       print_string[chars_left] = save_char;
-                       pb->crs = pb->buf + chars_to_add - chars_left;
-               }
-       }
-
-       if (pb->echo)
-               printk("%s", print_string);
-
-       spin_unlock_bh(&print_lock);
+       va_start(args, fmt);
+       i = vscnprintf(buf, len, fmt, args);
+       va_end(args);
+       return i;
 }
 
 /**