Thread (9 messages) flat view 9 messages, 4 authors, 2020-12-26

RE: [PATCH] nfp: remove h from printk format specifier

From: David Laight <hidden>
Date: 2020-12-26 20:43:03
Also in: bpf, lkml

From: Tom Rix
Sent: 25 December 2020 14:57
...
quoted
Kernel code doesn't use a signed char or short with %hx or %hu very often
but in case you didn't already know, any signed char/short emitted with
anything like %hx or %hu needs to be left alone as sign extension occurs so:
Yes, this would also effect checkpatch.
Does the kernel printf do the masking for %hx and %hhx?
A quick check I did showed that (at least some versions of) glibc does.
But the printf builtin in bash doesn't.

If the masking is there then %h[diux] and %hh[diux] are valid
even though the varargs supplied parameter is always extended to
at least the size of int.

This is even true if the parameter might be large.
For instance doing:
	..., "%hh02x:%hh02x:%hh02x:%hh02x", x >> 24, x >> 16, x >> 8, x);
will generate slightly smaller code than masking the passed values.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help