Improve sdhci slot_printf() debug printing.

Currently slot_printf() uses two printf() calls to print the
device-slot name, and actual message. When other printf()s are
ongoing in parallel this can lead to interleaved message on the console,
which is especially unhelpful for debugging or error messages.

Take a hit on the stack and vsnprintf() the message to the buffer.
This way it can be printed along with the device-slot name in one go
avoiding console gibberish.

Reviewed by:	marius
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D19747
This commit is contained in:
Bjoern A. Zeeb 2019-06-08 15:24:03 +00:00
parent 6e40542a4e
commit 27d72fe14a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=348801

View File

@ -185,15 +185,20 @@ sdhci_getaddr(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
static int
slot_printf(const struct sdhci_slot *slot, const char * fmt, ...)
{
char buf[128];
va_list ap;
int retval;
retval = printf("%s-slot%d: ",
device_get_nameunit(slot->bus), slot->num);
/*
* Make sure we print a single line all together rather than in two
* halves to avoid console gibberish bingo.
*/
va_start(ap, fmt);
retval += vprintf(fmt, ap);
retval = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
retval += printf("%s-slot%d: %s",
device_get_nameunit(slot->bus), slot->num, buf);
return (retval);
}