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 X-Spam-Level: X-Spam-Status: No, score=-23.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5DA7C07E95 for ; Wed, 7 Jul 2021 20:31:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9360B61CBB for ; Wed, 7 Jul 2021 20:31:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231359AbhGGUeV (ORCPT ); Wed, 7 Jul 2021 16:34:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230120AbhGGUeV (ORCPT ); Wed, 7 Jul 2021 16:34:21 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DD33C061574 for ; Wed, 7 Jul 2021 13:31:40 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id f13so7525835lfh.6 for ; Wed, 07 Jul 2021 13:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WK/UppGz71jkba2Ll+L/TuQuuPyl95ERCqbRa/Kjsng=; b=FSqoFPJdoDp0fQFVFmgACdu+RsTBYS6NEnKKjiyts1bU2UXWQczZw6EcT+rtRpRZC9 /MrzUA7pCtAzqijIcSp1iBVFa0LsV1MryY0RUBPgg74FFM1PhinqG7lJ17YlbxIMxott XUqEZnTK3/EoGhPaPyCmuWHOC+UH3RkXbDwBa6AEw15C4LMzm8LDcK4ez0XWMdhKZHsb PpPd05Kyh6/UXVjhj/3jkQHTA5pxu2zjORv7VKHQ503Uxo+gOiKADo2lY4ObP/SoHPPa V98c7llgs4ePbWcMdO4yPJPF8tqfHlO20oo6ifhqNbh2KoJyNKW90Dn5oQ6N6r9fmUid NF+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WK/UppGz71jkba2Ll+L/TuQuuPyl95ERCqbRa/Kjsng=; b=qD7bS82b2gC4QDPiQvbYHxiwpnystOcD0ccscIiuvVvCKvcCsX9dHOXpTvj7rJvMgS MKJW0JCyjwIts3xNXq0mYYL4ehiG8UzWYX4iViCcXlOHXbjFf3bMOlR3DHBAK02cpqdE esy1NeqLi1S/W6qkkmhzb01E0E+2B7OlpMMSS80yo0hUgE1CO1+VMWvMS1Cb4nEgXAbS dEXOaoyQroaprnY8vwG6hireyaTtgScRRQrtJKbyvpB915Q95yW0VFv8fsb12ntCWFXR EFd5yk/Mk8l0UA6VMpLfJOb5REUSYX2I9YBIF7d9Uo0SdWusVLc1g1eRfvX1wlfd7Fzy M0Cw== X-Gm-Message-State: AOAM532UmuNNZ00Dr/eZ/nSmItLo9clJYjhGe8pMuBan1cpcjFA7FhV2 hw06QyB9YxgCD32vBroqi4QiRvA5fsVorfbAgKTR1Q== X-Google-Smtp-Source: ABdhPJx/JTBDMrZxnW4BiPJjE/ztABpvFp2gHqhIACrYNIc20OQaJES1GsGTaYegI7OzbVCkRjN1rvOz+8mShnoBZiQ= X-Received: by 2002:a2e:8708:: with SMTP id m8mr20831340lji.244.1625689898523; Wed, 07 Jul 2021 13:31:38 -0700 (PDT) MIME-Version: 1.0 References: <20210704202756.29107-1-ojeda@kernel.org> <20210704202756.29107-5-ojeda@kernel.org> In-Reply-To: <20210704202756.29107-5-ojeda@kernel.org> From: Nick Desaulniers Date: Wed, 7 Jul 2021 13:31:18 -0700 Message-ID: Subject: Re: [PATCH 04/17] vsprintf: add new `%pA` format specifier To: ojeda@kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho , Boqun Feng , Sumera Priyadarsini , Michael Ellerman , Sven Van Asbroeck , Gary Guo , Boris-Chengbiao Zhou , Fox Chen , Ayaan Zaidi , Douglas Su , Yuki Okushi Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: rust-for-linux@vger.kernel.org On Sun, Jul 4, 2021 at 1:29 PM wrote: > > From: Miguel Ojeda > > This patch adds a format specifier `%pA` to `vsprintf` which formats > a pointer as `core::fmt::Arguments`. Doing so allows us to directly > format to the internal buffer of `printf`, so we do not have to use > a temporary buffer on the stack to pre-assemble the message on > the Rust side. > > This specifier is intended only to be used from Rust and not for C, so > `checkpatch.pl` is intentionally unchanged to catch any misuse. > > Co-developed-by: Alex Gaynor > Signed-off-by: Alex Gaynor > Co-developed-by: Geoffrey Thomas > Signed-off-by: Geoffrey Thomas > Co-developed-by: Finn Behrens > Signed-off-by: Finn Behrens > Co-developed-by: Adam Bratschi-Kaye > Signed-off-by: Adam Bratschi-Kaye > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Co-developed-by: Boqun Feng > Signed-off-by: Boqun Feng > Co-developed-by: Sumera Priyadarsini > Signed-off-by: Sumera Priyadarsini > Co-developed-by: Michael Ellerman > Signed-off-by: Michael Ellerman > Co-developed-by: Sven Van Asbroeck > Signed-off-by: Sven Van Asbroeck > Co-developed-by: Gary Guo > Signed-off-by: Gary Guo > Co-developed-by: Boris-Chengbiao Zhou > Signed-off-by: Boris-Chengbiao Zhou > Co-developed-by: Fox Chen > Signed-off-by: Fox Chen > Co-developed-by: Ayaan Zaidi > Signed-off-by: Ayaan Zaidi > Co-developed-by: Douglas Su > Signed-off-by: Douglas Su > Co-developed-by: Yuki Okushi > Signed-off-by: Yuki Okushi > Signed-off-by: Miguel Ojeda > --- > lib/vsprintf.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index f0c35d9b65b..e7afe954004 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -2182,6 +2182,10 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode, > return widen_string(buf, buf - buf_start, end, spec); > } > > +#ifdef CONFIG_RUST > +char *rust_fmt_argument(char* buf, char* end, void *ptr); Which patch in the series adds the definition of rust_fmt_argument? Sorry, I haven't looked through the entire series yet, but I don't think it was an earlier patch in the series. If it's later in the series, you may want to rebase this to be after (or combine it with the patch that provides the definition). For instance, let's say the first half of this series was accepted/merged, but not the latter half. It would be weird to provide such definitions/calls to undefined symbols. > +#endif > + > /* Disable pointer hashing if requested */ > bool no_hash_pointers __ro_after_init; > EXPORT_SYMBOL_GPL(no_hash_pointers); > @@ -2335,6 +2339,10 @@ early_param("no_hash_pointers", no_hash_pointers_enable); > * > * Note: The default behaviour (unadorned %p) is to hash the address, > * rendering it useful as a unique identifier. > + * > + * There is also a '%pA' format specifier, but it is only intended to be used > + * from Rust code to format core::fmt::Arguments. Do *not* use it from C. > + * See rust/kernel/print.rs for details. > */ > static noinline_for_stack > char *pointer(const char *fmt, char *buf, char *end, void *ptr, > @@ -2407,6 +2415,10 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, > return device_node_string(buf, end, ptr, spec, fmt + 1); > case 'f': > return fwnode_string(buf, end, ptr, spec, fmt + 1); > +#ifdef CONFIG_RUST > + case 'A': > + return rust_fmt_argument(buf, end, ptr); > +#endif > case 'x': > return pointer_string(buf, end, ptr, spec); > case 'e': > -- > 2.32.0 > -- Thanks, ~Nick Desaulniers