<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/lib/vsprintf.c, branch v4.5</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v4.5</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v4.5'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2016-02-12T02:35:48Z</updated>
<entry>
<title>vsprintf: kptr_restrict is okay in IRQ when 2</title>
<updated>2016-02-12T02:35:48Z</updated>
<author>
<name>Jason A. Donenfeld</name>
<email>Jason@zx2c4.com</email>
</author>
<published>2016-02-12T00:13:00Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=7eb391299419a03cbe0fa5ab0e6b0932e42c7a36'/>
<id>urn:sha1:7eb391299419a03cbe0fa5ab0e6b0932e42c7a36</id>
<content type='text'>
The kptr_restrict flag, when set to 1, only prints the kernel address
when the user has CAP_SYSLOG.  When it is set to 2, the kernel address
is always printed as zero.  When set to 1, this needs to check whether
or not we're in IRQ.

However, when set to 2, this check is unneccessary, and produces
confusing results in dmesg.  Thus, only make sure we're not in IRQ when
mode 1 is used, but not mode 2.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Jason A. Donenfeld &lt;Jason@zx2c4.com&gt;
Cc: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Cc: Kees Cook &lt;keescook@chromium.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib/vsprintf: factor out %pN[F] handler as netdev_bits()</title>
<updated>2016-01-16T19:17:30Z</updated>
<author>
<name>Andy Shevchenko</name>
<email>andriy.shevchenko@linux.intel.com</email>
</author>
<published>2016-01-16T00:59:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5b17aecfcdd3dc82c237677f5efc9a44deeaa39e'/>
<id>urn:sha1:5b17aecfcdd3dc82c237677f5efc9a44deeaa39e</id>
<content type='text'>
Move switch case to the netdev_features_string() and rename it to
netdev_bits().  In the future we can extend it as needed.

Here we replace the fallback of %pN from '%p' with possible flags to
sticter '0x%p' without any flags variation.

Signed-off-by: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Cc: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib/vsprintf: refactor duplicate code to special_hex_number()</title>
<updated>2016-01-16T19:17:30Z</updated>
<author>
<name>Andy Shevchenko</name>
<email>andriy.shevchenko@linux.intel.com</email>
</author>
<published>2016-01-16T00:59:18Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=3cab1e711297c4fbc526ca9b802ef61894c06545'/>
<id>urn:sha1:3cab1e711297c4fbc526ca9b802ef61894c06545</id>
<content type='text'>
special_hex_number() is a helper to print a fixed size type in a hex
format with '0x' prefix, zero padding, and small letters.  In the module
we have already several copies of such code.  Consolidate them under
special_hex_number() helper.

There are couple of differences though.

It seems nobody cared about the output in case of CONFIG_KALLSYMS=n,
when printing symbol address, because the asked field width is not
enough to care last 2 characters in the string represantation of the
pointer.  Fixed here.

The %pNF specifier used to be allowed with a specific field width,
though there is neither any user of it nor mention the possibility in
the documentation.

Signed-off-by: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Cc: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib/vsprintf.c: warn about too large precisions and field widths</title>
<updated>2016-01-16T19:17:27Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>linux@rasmusvillemoes.dk</email>
</author>
<published>2016-01-16T00:58:44Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=4d72ba014b4b0913f448ccaaaa2e8b39c54e3738'/>
<id>urn:sha1:4d72ba014b4b0913f448ccaaaa2e8b39c54e3738</id>
<content type='text'>
The field width is overloaded to pass some extra information for some %p
extensions (e.g.  #bits for %pb).  But we might silently truncate the
passed value when we stash it in struct printf_spec (see e.g.
"lib/vsprintf.c: expand field_width to 24 bits").  Hopefully 23 value
bits should now be enough for everybody, but if not, let's make some
noise.

Do the same for the precision.  In both cases, clamping seems more
sensible than truncating.  While, according to POSIX, "A negative
precision is taken as if the precision were omitted.", the kernel's
printf has always treated that case as if the precision was 0, so we use
that as lower bound.  For the field width, the smallest representable
value is actually -(1&lt;&lt;23), but a negative field width means 'set the
LEFT flag and use the absolute value', so we want the absolute value to
fit.

Signed-off-by: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Cc: Al Viro &lt;viro@ZenIV.linux.org.uk&gt;
Cc: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Cc: Kees Cook &lt;keescook@chromium.org&gt;
Cc: Maurizio Lombardi &lt;mlombard@redhat.com&gt;
Cc: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib/vsprintf.c: help gcc make number() smaller</title>
<updated>2016-01-16T19:17:26Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>linux@rasmusvillemoes.dk</email>
</author>
<published>2016-01-16T00:58:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1c7a8e622e84c9164dd665f5ad4879eac71bdc1e'/>
<id>urn:sha1:1c7a8e622e84c9164dd665f5ad4879eac71bdc1e</id>
<content type='text'>
One consequence of the reorganization of struct printf_spec to make
field_width 24 bits was that number() gained about 180 bytes.  Since
spec is never passed to other functions, we can help gcc make number()
lose most of that extra weight by using local variables for the field
width and precision.

Reviewed-by: Andy Shevchenko &lt;andy.shevchenko@gmail.com&gt;
Signed-off-by: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Cc: Al Viro &lt;viro@ZenIV.linux.org.uk&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Cc: Kees Cook &lt;keescook@chromium.org&gt;
Cc: Maurizio Lombardi &lt;mlombard@redhat.com&gt;
Cc: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib/vsprintf.c: expand field_width to 24 bits</title>
<updated>2016-01-16T19:17:26Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>linux@rasmusvillemoes.dk</email>
</author>
<published>2016-01-16T00:58:37Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d048419311ff16ba420f4b1bdf93a3d74057b53a'/>
<id>urn:sha1:d048419311ff16ba420f4b1bdf93a3d74057b53a</id>
<content type='text'>
Maurizio Lombardi reported a problem [1] with the %pb extension: It
doesn't work for sufficiently large bitmaps, since the size is stashed
in the field_width field of the struct printf_spec, which is currently
an s16.  Concretely, this manifested itself in
/sys/bus/pseudo/drivers/scsi_debug/map being empty, since the bitmap
printer got a size of 0, which is the 16 bit truncation of the actual
bitmap size.

We do want to keep struct printf_spec at 8 bytes so that it can cheaply
be passed by value.  The qualifier field is only used for internal
bookkeeping in format_decode, so we might as well use a local variable
for that.  This gives us an additional 8 bits, which we can then use for
the field width.

To stay in 8 bytes, we need to do a little rearranging and make the type
member a bitfield as well.  For consistency, change all the members to
bit fields.  gcc doesn't generate much worse code with these changes (in
fact, bloat-o-meter says we save 300 bytes - which I think is a little
surprising).

I didn't find a BUILD_BUG/compiletime_assertion/... which would work
outside function context, so for now I just open-coded it.

[1] http://thread.gmane.org/gmane.linux.kernel/2034835

[akpm@linux-foundation.org: avoid open-coded BUILD_BUG_ON]
Signed-off-by: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Reported-by: Maurizio Lombardi &lt;mlombard@redhat.com&gt;
Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Cc: Al Viro &lt;viro@ZenIV.linux.org.uk&gt;
Cc: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Cc: Kees Cook &lt;keescook@chromium.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib/vsprintf.c: eliminate potential race in string()</title>
<updated>2016-01-16T19:17:26Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>linux@rasmusvillemoes.dk</email>
</author>
<published>2016-01-16T00:58:34Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=34fc8b9076254513e00607134792a1b67483d2cf'/>
<id>urn:sha1:34fc8b9076254513e00607134792a1b67483d2cf</id>
<content type='text'>
If the string corresponding to a %s specifier can change under us, we
might end up copying a \0 byte to the output buffer.  There might be
callers who expect the output buffer to contain a genuine C string whose
length is exactly the snprintf return value (assuming truncation hasn't
happened or has been checked for).

We can avoid this by only passing over the source string once, stopping
the first time we meet a nul byte (or when we reach the given
precision), and then letting widen_string() handle left/right space
padding.  As a small bonus, this code reuse also makes the generated
code slightly smaller.

Signed-off-by: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Cc: Al Viro &lt;viro@ZenIV.linux.org.uk&gt;
Cc: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Cc: Kees Cook &lt;keescook@chromium.org&gt;
Cc: Maurizio Lombardi &lt;mlombard@redhat.com&gt;
Cc: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib/vsprintf.c: move string() below widen_string()</title>
<updated>2016-01-16T19:17:26Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>linux@rasmusvillemoes.dk</email>
</author>
<published>2016-01-16T00:58:31Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=95508cfa10503bbe5adb78bd1b2b56a01ab3dd2d'/>
<id>urn:sha1:95508cfa10503bbe5adb78bd1b2b56a01ab3dd2d</id>
<content type='text'>
This is pure code movement, making sure the widen_string() helper is
defined before the string() function.

Signed-off-by: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Cc: Al Viro &lt;viro@ZenIV.linux.org.uk&gt;
Cc: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Cc: Kees Cook &lt;keescook@chromium.org&gt;
Cc: Maurizio Lombardi &lt;mlombard@redhat.com&gt;
Cc: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib/vsprintf.c: pull out padding code from dentry_name()</title>
<updated>2016-01-16T19:17:25Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>linux@rasmusvillemoes.dk</email>
</author>
<published>2016-01-16T00:58:28Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=cfccde04e28d26e9f102e535b7358bf6cf3bc6fb'/>
<id>urn:sha1:cfccde04e28d26e9f102e535b7358bf6cf3bc6fb</id>
<content type='text'>
Pull out the logic in dentry_name() which handles field width space
padding, in preparation for reusing it from string().  Rename the
widen() helper to move_right(), since it is used for handling the
!(flags &amp; LEFT) case.

Signed-off-by: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Cc: Al Viro &lt;viro@ZenIV.linux.org.uk&gt;
Cc: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Cc: Kees Cook &lt;keescook@chromium.org&gt;
Cc: Maurizio Lombardi &lt;mlombard@redhat.com&gt;
Cc: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib/vsprintf: add %*pg format specifier</title>
<updated>2016-01-06T17:55:29Z</updated>
<author>
<name>Dmitry Monakhov</name>
<email>dmonakhov@openvz.org</email>
</author>
<published>2015-04-13T12:31:35Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1031bc589228ca35b3b6fb3dfe4656c0da5fbeb4'/>
<id>urn:sha1:1031bc589228ca35b3b6fb3dfe4656c0da5fbeb4</id>
<content type='text'>
This allow to directly print block_device name.
Currently one should use bdevname() with temporal char buffer.
This is very ineffective because bloat stack usage for deep IO call-traces

Example:
	%pg  -&gt;    sda, sda1 or loop0p1

[AV: fixed a minor braino - position updates should not be dependent
upon having reached the of buffer]

Signed-off-by: Dmitry Monakhov &lt;dmonakhov@openvz.org&gt;
Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
</content>
</entry>
</feed>
