Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3278259pxv; Sun, 4 Jul 2021 13:30:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUR4npzuIBFe8F+FP817s/0xbReSIiNRds7/EIVAtpn8R/3xpSPDlOdKI0HKx/0mDUXMga X-Received: by 2002:a05:6638:1606:: with SMTP id x6mr572602jas.98.1625430612500; Sun, 04 Jul 2021 13:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625430612; cv=none; d=google.com; s=arc-20160816; b=eCMcrRMFT3IBqtl6CI7AtuPBKVuLL9kNKsGcWqL+/+s6yiLtd3nLkaJcGGkwqiihnW 0fDzUlEqNfypDcSDw3iLZHt2+5CtCWXels7Qb3HVKGmMgNoWJ+Q5ouWfRyCEzf0jvKnF 4o78JKgKGYx7JQaNPsdWrnecugXIpDQLAq48DAiDVDSmbLm2/MAr7LNQ2wKw1UMmQm8r CKpY1zKXeQn1lqbQPJ2O3YMBylA8tVfq7Psc2nLnvmT9x65z+S+urtCSxamb4lsCxQ0t pzK063bcrYfd5ycD869IvA5bx8WbAJ0NNlcOdfN6URMfOlqdBG4NXvImm9AUZfvOW4qh 8ZNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MPvoTSYNR7R7wQOGgQ5FqEk56C7/Hy59GS3Oxcwarsw=; b=0jdn+U5/9fjfUAlA8FRfbVpdKYlYJBKskai1aNwh6HU2Ev9daDUaDOw32KQqEHj5Of JOE2VHk6wwqwFwmti9jVwMq05pR8rhSVnrD13olBapTHzq9vN0nwVW2eHqplO1xWvIUi +1U8zy2RlHDlU43SKTA5nL688pS859YqlIsb6RuyxH2fOuJoNvr/BDzOn4ua2Tly6sYP GfcJZesUVBjteElysFBQrAK2Nxiod7u89UTmA3wFEXqUQMXyK6/r8QGKwbMl/ug/tIoc coIa/0WET6arfYEOLDH0ChBoAoYL/nfY4vqkM5jeh30h3Y36OoJGA/LFUG2mtua7giFl DhXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LC8aFv8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si11604409ioj.78.2021.07.04.13.30.01; Sun, 04 Jul 2021 13:30:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LC8aFv8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230056AbhGDUb2 (ORCPT + 99 others); Sun, 4 Jul 2021 16:31:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:36800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbhGDUbZ (ORCPT ); Sun, 4 Jul 2021 16:31:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E8446613DD; Sun, 4 Jul 2021 20:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625430529; bh=AGapwzpPs5XBP4WvEM+GDuQKLpaiGR7OCL0hbLs6unY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LC8aFv8SQvWWPRE2gcZTcKxeRBxFiOpB24qXs+aG7VwwYRsCkJMjLgxO7VmgTj1k3 0nXhlbmHCQXSRKNgS7WRthTxaeHEJWw8Zg/vtahd5uOs8fcj1qCYStUn79XWWU+Gm9 41cHmkT0pE0nbImVWyib8VtGqU9kusVZGqIobd7LM6m2Y+QpCLavZ5M1GhVOZEr1WU /BfalH/67vQpWM+AQJl9N2WmHasC5xHPLt5GyqVh4gpWz+yG6k2w+UilnSJCExSZdC Ewpe90KC8md4IjNLNJsvbtp6GSC6xINWzxsZ6CsjqSHf+ckrupPADx0TnuOLmvKqTM xJye/qMo/AyhQ== From: ojeda@kernel.org To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Miguel Ojeda , 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 Subject: [PATCH 04/17] vsprintf: add new `%pA` format specifier Date: Sun, 4 Jul 2021 22:27:43 +0200 Message-Id: <20210704202756.29107-5-ojeda@kernel.org> In-Reply-To: <20210704202756.29107-1-ojeda@kernel.org> References: <20210704202756.29107-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); +#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