From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
Patrick Delaunay <patrick.delaunay@foss.st.com>,
u-boot@lists.denx.de
Subject: Re: [PATCH 2/8] lib: printf code %pUs for GUID text representation
Date: Tue, 18 Jan 2022 11:48:11 +0900 [thread overview]
Message-ID: <20220118024811.GB30001@laputa> (raw)
In-Reply-To: <20220116151441.219566-3-heinrich.schuchardt@canonical.com>
On Sun, Jan 16, 2022 at 04:14:35PM +0100, Heinrich Schuchardt wrote:
> In different places text representations are used for GUIDs, e.g.
>
> * command efidebug
> * command part list for GPT partitions
>
> To allow reducing code duplication introduce a new printf code %pUs.
> It will call uuid_guid_get_str() to get a text representation. If none is
> found it will fallback to %pUl and print a hexadecimal representation.
I think the idea is good.
Moreover, when you add a new format specifier to printf() routine,
it would also be good to add a document so that people won't bustle
around the code to find an appropriate format string.
Not only to "%pU*", but also others including "%pD" and "%ls" that you added.
# See linux's Documentation/core-api/printk-formats.rst.
-Takahiro Akashi
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
> lib/vsprintf.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index de9f236b90..2c0cc1647e 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -255,8 +255,8 @@ static char *number(char *buf, char *end, u64 num,
> return buf;
> }
>
> -static char *string(char *buf, char *end, char *s, int field_width,
> - int precision, int flags)
> +static char *string(char *buf, char *end, const char *s, int field_width,
> + int precision, int flags)
> {
> int len, i;
>
> @@ -387,12 +387,14 @@ static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width,
> * %pUB: 01020304-0506-0708-090A-0B0C0D0E0F10
> * %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10
> * %pUL: 04030201-0605-0807-090A-0B0C0D0E0F10
> + * %pUs: GUID text representation if known or fallback to %pUl
> */
> static char *uuid_string(char *buf, char *end, u8 *addr, int field_width,
> int precision, int flags, const char *fmt)
> {
> char uuid[UUID_STR_LEN + 1];
> int str_format;
> + const char *str;
>
> switch (*(++fmt)) {
> case 'L':
> @@ -404,6 +406,13 @@ static char *uuid_string(char *buf, char *end, u8 *addr, int field_width,
> case 'B':
> str_format = UUID_STR_FORMAT_STD | UUID_STR_UPPER_CASE;
> break;
> + case 's':
> + str = uuid_guid_get_str(addr);
> + if (str)
> + return string(buf, end, str,
> + field_width, precision, flags);
> + str_format = UUID_STR_FORMAT_GUID;
> + break;
> default:
> str_format = UUID_STR_FORMAT_STD;
> break;
> --
> 2.33.1
>
next prev parent reply other threads:[~2022-01-18 2:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-16 15:14 [PATCH 0/8] efi_loader: simplify printing GUIDs Heinrich Schuchardt
2022-01-16 15:14 ` [PATCH 1/8] lib: compile uuid_guid_get_str if CONFIG_LIB_UUID=y Heinrich Schuchardt
2022-01-21 15:20 ` Simon Glass
2022-01-16 15:14 ` [PATCH 2/8] lib: printf code %pUs for GUID text representation Heinrich Schuchardt
2022-01-18 2:48 ` AKASHI Takahiro [this message]
2022-01-16 15:14 ` [PATCH 3/8] disk: simplify part_print_efi() Heinrich Schuchardt
2022-01-21 15:20 ` Simon Glass
2022-01-16 15:14 ` [PATCH 4/8] sandbox: imply PARTITION_TYPE_GUID Heinrich Schuchardt
2022-01-21 15:20 ` Simon Glass
2022-01-16 15:14 ` [PATCH 5/8] test: add test for %pUs Heinrich Schuchardt
2022-01-21 15:20 ` Simon Glass
2022-01-16 15:14 ` [PATCH 6/8] cmd: efidebug: simplify printing GUIDs Heinrich Schuchardt
2022-01-21 15:20 ` Simon Glass
2022-01-21 16:03 ` Heinrich Schuchardt
2022-01-21 16:53 ` Simon Glass
2022-01-24 7:23 ` AKASHI Takahiro
2022-01-24 8:25 ` Heinrich Schuchardt
2022-01-25 0:19 ` AKASHI Takahiro
2022-01-16 15:14 ` [PATCH 7/8] efi_loader: user %pUs for " Heinrich Schuchardt
2022-01-21 15:20 ` Simon Glass
2022-01-16 15:14 ` [PATCH 8/8] cmd: printenv: simplify " Heinrich Schuchardt
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=20220118024811.GB30001@laputa \
--to=takahiro.akashi@linaro.org \
--cc=heinrich.schuchardt@canonical.com \
--cc=patrick.delaunay@foss.st.com \
--cc=rasmus.villemoes@prevas.dk \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/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