From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Petr Mladek <pmladek@suse.com>
Cc: "Uwe Kleine-König" <uwe@kleine-koenig.org>,
"Joe Perches" <joe@perches.com>,
"Andy Shevchenko" <andy.shevchenko@gmail.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Jonathan Corbet" <corbet@lwn.net>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/1] printf: add support for printing symbolic error names
Date: Tue, 15 Oct 2019 14:17:43 +0200 [thread overview]
Message-ID: <226edb75-b954-cbb4-4ba5-6529a725fe43@rasmusvillemoes.dk> (raw)
In-Reply-To: <20191014130247.rag2g7qz54uiw54z@pathway.suse.cz>
On 14/10/2019 15.02, Petr Mladek wrote:
> On Fri 2019-10-11 15:36:17, Rasmus Villemoes wrote:
>> It has been suggested several times to extend vsnprintf() to be able
>> to convert the numeric value of ENOSPC to print "ENOSPC". This
>> implements that as a %p extension: With %pe, one can do
>
> Reviewed-by: Petr Mladek <pmladek@suse.com>
>
> I like the patch. There are only two rather cosmetic things.
>
>> diff --git a/lib/errname.c b/lib/errname.c
>> new file mode 100644
>> index 000000000000..30d3bab99477
>> --- /dev/null
>> +++ b/lib/errname.c
>> +const char *errname(int err)
>> +{
>> + bool pos = err > 0;
>> + const char *name = __errname(err > 0 ? err : -err);
>> +
>> + return name ? name + pos : NULL;
>
> This made me to check C standard. It seems that "true" really has
> to be "1".
>
> But I think that I am not the only one who is not sure.
> I would prefer to make it less tricky and use, for example:
>
> const char *name = __errname(err > 0 ? err : -err);
> if (!name)
> return NULL;
>
> return err > 0 ? name + 1 : name;
I didn't even stop to think that using the value of a comparison
operator/bool in arithmetic might be the littlest bit surprising for C
programmers. But your suggestion isn't terrible, so go ahead and write
it that way. And can I get you to fix the missing "-" in the MIPS
"EDQUOT" special case while you're at it?
>> +static void __init
>> +errptr(void)
>> +{
>> + char buf[PLAIN_BUF_SIZE];
>> +
>> + test("-1234", "%pe", ERR_PTR(-1234));
>> +
>> + /* Check that %pe with a non-ERR_PTR gets treated as ordinary %p. */
>> + BUILD_BUG_ON(IS_ERR(PTR));
>> + snprintf(buf, sizeof(buf), "(%p)", PTR);
>> + test(buf, "(%pe)", PTR);
>
> There is a small race. "(____ptrval____)" is used for %p before
> random numbers are initialized. The switch is done via workqueue
> work, see enable_ptr_key_workfn(). It means that it can be done
> in parallel.
I know.
> I doubt that anyone would ever hit the race. But it could be very confusing
> and hard to debug.
I thought about it and decided not to care, as long as the errptr test
comes after the hashing test, because if the hashing is not initialized
then one gets a warning. I also considered setting a flag in that case
and then skipping the errptr hash test, but again, decided that the
warning would be enough.
> I would replace it with:
> test_hashed("%pe", PTR);
Sure, that will repeat the warning, but it doesn't seem to prevent a
false positive: Between plain_hash_to_buffer emitting the warning (and
returning 0) and the caller test_hashed() then performing the test()
against the buffer contents, the hash can become initialized and thus
change how %p[e] gets formatted. But ok, perhaps it is cleaner to reuse
test_hashed and avoid the local buffer in errptr. So yeah, I suppose
this on top is fine:
diff --git a/lib/test_printf.c b/lib/test_printf.c
index 4fa0ccf58420..030daeb4fe21 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -596,14 +596,11 @@ flags(void)
static void __init
errptr(void)
{
- char buf[PLAIN_BUF_SIZE];
-
test("-1234", "%pe", ERR_PTR(-1234));
/* Check that %pe with a non-ERR_PTR gets treated as ordinary %p. */
BUILD_BUG_ON(IS_ERR(PTR));
- snprintf(buf, sizeof(buf), "(%p)", PTR);
- test(buf, "(%pe)", PTR);
+ test_hashed("%pe", PTR);
#ifdef CONFIG_SYMBOLIC_ERRNAME
test("(-ENOTSOCK)", "(%pe)", ERR_PTR(-ENOTSOCK));
> If would like to have the two things fixed. I am not sure if you want
> to send one more revision. Or I could also change it by follow
> up patch when pushing.
I prefer you to fold in both changes instead of an extra patch, and if
you can't, I'll send a new revision.
Rasmus
next prev parent reply other threads:[~2019-10-15 12:17 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-30 21:46 [PATCH] printf: add support for printing symbolic error codes Rasmus Villemoes
2019-08-30 21:53 ` Joe Perches
2019-08-30 22:03 ` Rasmus Villemoes
2019-08-30 22:21 ` Joe Perches
2019-08-30 22:50 ` Rasmus Villemoes
2019-09-02 9:07 ` David Laight
2019-08-31 9:38 ` kbuild test robot
2019-09-02 15:29 ` Uwe Kleine-König
2019-09-04 9:13 ` Rasmus Villemoes
2019-09-04 9:21 ` Uwe Kleine-König
2019-09-04 16:19 ` Andy Shevchenko
2019-09-04 16:28 ` Uwe Kleine-König
2019-09-05 11:40 ` Rasmus Villemoes
2019-09-09 20:38 ` [PATCH v2] " Rasmus Villemoes
2019-09-10 15:26 ` Andy Shevchenko
2019-09-11 0:15 ` Joe Perches
2019-09-11 6:43 ` Rasmus Villemoes
2019-09-11 9:37 ` Uwe Kleine-König
2019-09-11 10:14 ` Rasmus Villemoes
2019-09-15 9:43 ` Pavel Machek
2019-09-16 12:23 ` Uwe Kleine-König
2019-09-16 13:23 ` Rasmus Villemoes
2019-09-16 13:36 ` Uwe Kleine-König
2019-09-17 6:59 ` [PATCH v3] " Rasmus Villemoes
2019-09-25 14:36 ` Petr Mladek
2019-09-29 20:09 ` Rasmus Villemoes
2019-10-02 8:34 ` Petr Mladek
2019-10-05 21:48 ` Andrew Morton
2019-10-11 13:36 ` [PATCH v4 0/1] printf: add support for printing symbolic error names Rasmus Villemoes
2019-10-11 13:36 ` [PATCH v4 1/1] " Rasmus Villemoes
2019-10-14 5:51 ` Uwe Kleine-König
2019-10-14 13:02 ` Petr Mladek
2019-10-14 13:10 ` Andy Shevchenko
2019-10-15 12:17 ` Rasmus Villemoes [this message]
2019-10-15 13:44 ` David Laight
2019-10-15 19:07 ` [PATCH v5] " Rasmus Villemoes
2019-10-16 13:49 ` Andy Shevchenko
2019-10-16 14:52 ` Petr Mladek
2019-10-16 16:31 ` Andy Shevchenko
2019-10-17 15:02 ` Petr Mladek
2019-11-26 14:04 ` [PATCH v4 0/1] " Geert Uytterhoeven
2019-11-27 8:54 ` Petr Mladek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=226edb75-b954-cbb4-4ba5-6529a725fe43@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=andy.shevchenko@gmail.com \
--cc=corbet@lwn.net \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=uwe@kleine-koenig.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).