From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA622C433FE for ; Tue, 18 Jan 2022 02:48:25 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0171E80F9E; Tue, 18 Jan 2022 03:48:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YXkC/nPz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 260C781430; Tue, 18 Jan 2022 03:48:21 +0100 (CET) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5AA708083E for ; Tue, 18 Jan 2022 03:48:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pl1-x62f.google.com with SMTP id u11so17914137plh.13 for ; Mon, 17 Jan 2022 18:48:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=QfrIL9eCdc1XypYqqiYoMSa7Rq4aCunKs8f47+0d4Cg=; b=YXkC/nPzLXt8sFJqCIKgdzmw8LdXjYg46n54/BfOJQjWtiUzJseDPQOSGJQSOeD1QX KAjLlFLfAXaH1r5jP8WyVGZkRSarDVvMJ40V/ZnauND1bXDZQk5XSPDy+Uo55gIn4qnZ YbIOuhMecEYk756xFJdzEY0+loaPHj1w4WK4tbaFK7hIih8YEkRIGeP5MmeN524n6/gY uPnCAhv9CrGw9NKdAsnwVkMV28vwe0Cs+HEKbPjgk7y0CoGZLpneZQ5UxPTGaPBlrULv liwodyDMZg3Iz0zpOpGNXenpk2xGwU5Rc3pTG+gDyOWsmqcngKVs8xGPfv7T/GlNFVQN SA2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=QfrIL9eCdc1XypYqqiYoMSa7Rq4aCunKs8f47+0d4Cg=; b=hzyXit+131LZ1cd3jJHp/XA3UPOlVaC73GwiiWJw7NycOf925iWZQBTB/Oc52BaDgk yny0dzS+ILOEst2U6aEffMlRR4j88aDxQQuuTeFapHz/RklNp9kAqYLdh56hx+7lNxPq ldVywoN7lXDM4dskoUks8YBhnbPX5l9DttTltK/MiS7o+znQ039QRDFs3Sb47gprjM5V ndhz0Aesx7djFaun5fhVnp46sKvVjGbYaQiqJIOUWMW4RuuzZl2wrA8TJB1sV2Npox5a 58/4oCLBEtHsOk5xM9zvBXH0m2i/0cfjOX2yBYACNEgOUi4C4XrWgq/2ruJMrHqqObV7 DnOA== X-Gm-Message-State: AOAM530+Fwnkcqdh7BVuFlJJTHhf2RY1EUtBQXlt7EERrM57LrqDOLlq YyjXS4rvHEd3VjvUUrYsbVlpfQ== X-Google-Smtp-Source: ABdhPJw3v0IgYDl5rjyYaqyv0LLlysba8l3R/gy0vfyKCfZhkRgazomvBYEPWVsyx4vZJ9szQUBPbQ== X-Received: by 2002:a17:90b:4d8e:: with SMTP id oj14mr37704078pjb.232.1642474095499; Mon, 17 Jan 2022 18:48:15 -0800 (PST) Received: from laputa ([2400:4050:c3e1:100:bc1a:291e:ac91:be98]) by smtp.gmail.com with ESMTPSA id y126sm14646557pfy.40.2022.01.17.18.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jan 2022 18:48:14 -0800 (PST) Date: Tue, 18 Jan 2022 11:48:11 +0900 From: AKASHI Takahiro To: Heinrich Schuchardt Cc: Tom Rini , Simon Glass , Rasmus Villemoes , Patrick Delaunay , u-boot@lists.denx.de Subject: Re: [PATCH 2/8] lib: printf code %pUs for GUID text representation Message-ID: <20220118024811.GB30001@laputa> Mail-Followup-To: AKASHI Takahiro , Heinrich Schuchardt , Tom Rini , Simon Glass , Rasmus Villemoes , Patrick Delaunay , u-boot@lists.denx.de References: <20220116151441.219566-1-heinrich.schuchardt@canonical.com> <20220116151441.219566-3-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220116151441.219566-3-heinrich.schuchardt@canonical.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean 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 > --- > 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 >