On Tue 10-04-18 19:56:14, Rasmus Villemoes wrote: > Here's an idea that does require rewriting all the existing > reiserfs_warning etc. calls, but avoids all the fragile vararg handling > and adds proper compile-time format string checking: > > Have reiserfs_warning (and friends) be a macro that expands to > > reiserfs_printf_start(); > __reiserfs_warning(the arguments); > reiserfs_printf_stop(); > > where printf_start would take a spinlock and reset some bookkeeping > variables. Then all the sprintf_de_head etc. helpers would have a > prototype like > > const char *sprintf_de_head(struct reiserfs_de_head *deh) > > and they would print their output to the current error_buf, updating the > above-mentioned bookkeeping variable(s) and return a pointer to the > start of the area they printed to. So > > reiserfs_warning("bla %a", deh) > > would get changed to > > reiserfs_warning("bla %s", sprintf_de_head(deh)) > > Basically, the current error_buf would only be used for holding the > result of the custom specifiers, everything else goes directly to > printk's output buffer, so no need to make error_buf larger (a single > printk is limited to 1024 bytes anyway...), and fmt_buf goes away > completely. That reduction in static footprint should make up for at > least some of the bloat caused by the extra code the new > reiserfs_warning would generate. Also, I don't think this should make us > hold the spinlock (much) longer than is currently the case, and > trivially solves the problem of not actually holding the spinlock when > passing the error_buf to printk. So I don't see how this would work for more complex warnings like: reiserfs_warning("bla %*d foo %a bar %llx %a", width, number, deh, another_number, deh2) Either we'd need some macro magic rewriting 'deh' and 'deh2' arguments to sprintf_de_head(deh) and sprintf_de_head(deh2) (which I don't see how we could do), rewrite the whole format string and then pass it to vsnprintf() or I don't see how we could get away without knowing how much from va_list vsnprinf() consumed... Honza -- Jan Kara <jack@xxxxxxxx> SUSE Labs, CR -- To unsubscribe from this list: send the line "unsubscribe reiserfs-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html