Skip to content

Commit 1e03a8e

Browse files
ajstephensnashif
authored andcommitted
printk: Standardize support for %%
Tweaks printk() internals to avoid unnecessary special case handling of %% formatting. Change-Id: I816b04b458f416a45fd06b5a7b3bebf27453c722 Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
1 parent a1d47ba commit 1e03a8e

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed

misc/printk.c

+46-45
Original file line numberDiff line numberDiff line change
@@ -84,54 +84,55 @@ static inline void _vprintk(const char *fmt, va_list ap)
8484
might_format = 1;
8585
}
8686
} else {
87-
if (*fmt == '%') {
88-
_char_out((int)'%');
89-
might_format = 0;
90-
} else {
91-
switch (*fmt) {
92-
case 'd':
93-
case 'i': {
94-
long d = va_arg(ap, long);
95-
if (d < 0) {
96-
_char_out((int)'-');
97-
d = -d;
98-
}
99-
_printk_dec_ulong(d);
100-
break;
101-
}
102-
case 'u': {
103-
unsigned long u = va_arg(
104-
ap, unsigned long);
105-
_printk_dec_ulong(u);
106-
break;
107-
}
108-
case 'x':
109-
case 'X':
110-
case 'p': {
111-
unsigned long x = va_arg(
112-
ap, unsigned long);
113-
_printk_hex_ulong(x);
114-
break;
115-
}
116-
case 's': {
117-
char *s = va_arg(ap, char *);
118-
while (*s)
119-
_char_out((int)(*s++));
120-
break;
87+
switch (*fmt) {
88+
case 'd':
89+
case 'i': {
90+
long d = va_arg(ap, long);
91+
92+
if (d < 0) {
93+
_char_out((int)'-');
94+
d = -d;
12195
}
122-
case 'c': {
123-
int c = va_arg(ap, int);
96+
_printk_dec_ulong(d);
97+
break;
98+
}
99+
case 'u': {
100+
unsigned long u = va_arg(
101+
ap, unsigned long);
102+
_printk_dec_ulong(u);
103+
break;
104+
}
105+
case 'x':
106+
case 'X':
107+
case 'p': {
108+
unsigned long x = va_arg(
109+
ap, unsigned long);
110+
_printk_hex_ulong(x);
111+
break;
112+
}
113+
case 's': {
114+
char *s = va_arg(ap, char *);
124115

125-
_char_out(c);
126-
break;
127-
}
128-
default:
129-
_char_out((int)'%');
130-
_char_out((int)*fmt);
131-
break;
132-
}
133-
might_format = 0;
116+
while (*s)
117+
_char_out((int)(*s++));
118+
break;
119+
}
120+
case 'c': {
121+
int c = va_arg(ap, int);
122+
123+
_char_out(c);
124+
break;
125+
}
126+
case '%': {
127+
_char_out((int)'%');
128+
break;
129+
}
130+
default:
131+
_char_out((int)'%');
132+
_char_out((int)*fmt);
133+
break;
134134
}
135+
might_format = 0;
135136
}
136137

137138
++fmt;

0 commit comments

Comments
 (0)