bcachefs: print_string_as_lines: avoid printing empty line
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 22 Apr 2025 10:03:33 +0000 (06:03 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:31 +0000 (20:14 -0400)
If the final line in in the message to be printed is blang, don't print
it.

This happens with indented printbufs - after a newline we emit spaces up
to the indent level.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/util.c

index 7e6ebe8cd9ea369c074fee31c141736a572dfca6..1cff407c8c9dcecba9d3af99d5fc3abf25d6ca42 100644 (file)
@@ -252,6 +252,16 @@ void bch2_prt_u64_base2(struct printbuf *out, u64 v)
        bch2_prt_u64_base2_nbits(out, v, fls64(v) ?: 1);
 }
 
+static bool string_is_spaces(const char *str)
+{
+       while (*str) {
+               if (*str != ' ')
+                       return false;
+               str++;
+       }
+       return true;
+}
+
 void bch2_print_string_as_lines(const char *prefix, const char *lines,
                                bool nonblocking)
 {
@@ -272,6 +282,9 @@ void bch2_print_string_as_lines(const char *prefix, const char *lines,
 
        while (*lines) {
                p = strchrnul(lines, '\n');
+               if (!*p && string_is_spaces(lines))
+                       break;
+
                printk("%s%.*s\n", prefix, (int) (p - lines), lines);
                if (!*p)
                        break;