Message ID | 20230714-cstring-debug-v1-1-4e7c3018dd4f@asahilina.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2386919vqm; Fri, 14 Jul 2023 02:51:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlEAHn+bMQv3F8hoZMYvrjmuL5o8ZrHqBtPWNmOhGQrpEdRcgBe26SX0HymyezmRDY8G+mGo X-Received: by 2002:a17:906:519c:b0:994:54e9:692c with SMTP id y28-20020a170906519c00b0099454e9692cmr229659ejk.1.1689328312862; Fri, 14 Jul 2023 02:51:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689328312; cv=none; d=google.com; s=arc-20160816; b=X6x54S0SSljLjyJZSB63ocJiM0i+v8mA9Y8Atr8GVXDnZGaP/7FTjxy9WmZasDV71H wS0Suvnz+81tVqw7I2J3svpyNmqX+j8JvHwJjnvdrhwoBoRqSVEDF6MjXnMVayecEPJ8 /Jp7z5liu+p3zQbXvCuXSlmhqxU76iirH+vpYVAEkqbd3Fu8LwenFhUteQEUTY5nKSd4 gd/p7chqFxNCFsc2mux4wO5yt6Pa+hfxFA7Yw2iC6TvLKSH2/PxqAEzZOkSQ+WHabGdn pCZfijjwe6RaA0U6HaytRvAr4s2EIvXggXmYqFDiFSbUlQlNikBb/SGteIdfL80sWAUs yfRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=PmVGEihQj+siomImaPG8tYAyrCdAjUR5Pp6QeqvwLiU=; fh=YdOJwOfHm/a56O5Pkv+e9miVlZAaA9UBMsMKdv/nH38=; b=NCy2T1/CYBefXyfbzXuHCNBTT5DfWMUFpXXNSil0/JrGQ/7MhpkQfZiw8rHbI38u5q I621q72OpQltL+qZ6tFT42PQ180REDI99sLhRho10sTiFvelj43C373wEZ0v0n7xb5sJ Aj+ML6R2TxmgxWjVeU5zqjyzXISQBSytc6qiWpksYZXLhiNifnXAJ1VvJpQ7HYroJGbH /UFIl2naO3DdDKfq5WZkeZTpR7UUXhSa/XKdmIwMZWmDL3fI30h5aDouXoaDc8fEItsf s/npBgWab+x5cHifVcYlzBknx1Yd86PXuOKEyatFUvMcaN/RGB4TOHTDCVMjaigU7ZXc zOwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=SW7iC9PL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z15-20020a1709064e0f00b00992af47620esi1478478eju.509.2023.07.14.02.51.29; Fri, 14 Jul 2023 02:51:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=SW7iC9PL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235828AbjGNJgX (ORCPT <rfc822;hadasmailinglist@gmail.com> + 99 others); Fri, 14 Jul 2023 05:36:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235742AbjGNJgI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 14 Jul 2023 05:36:08 -0400 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92DE6358E; Fri, 14 Jul 2023 02:36:06 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: linasend@asahilina.net) by mail.marcansoft.com (Postfix) with ESMTPSA id 64EE65BC9C; Fri, 14 Jul 2023 09:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1689326380; bh=xxvykvXcInvkp1nPJDBq3/LVlq3218mtzs6EEpgOuZM=; h=From:Date:Subject:To:Cc; b=SW7iC9PLblGwjy0uS43ESSW/CTTwGFLyA7BXzUeLnZBlYYClQOkSR1914QK8OPVTN whb4pXHsb8MzNqGrVxrGB2h9YLO9wpjogxw0VaaTMpEYJ4mc91FSi4tklMSZOvQYkg wa/lTzit4twzHZblAKxWYbB8IeWNCxSsnLOBfWc4JZQTi1xuCY8jaLuFSDIVdA0ubs nPmlbDtM0sbXxSy5V4YgYSoSVlsNLJe/tSrfJ2WXFdelBflnNAoFy5mv4YA4cpa7oy GyGrWGIvE0CvrssMJkX9Pd+m3hv64csNorB9EImvr5ZJOn6s1Ds19IHuekrBv5flOX BfJy6V18tUZlw== From: Asahi Lina <lina@asahilina.net> Date: Fri, 14 Jul 2023 18:19:33 +0900 Subject: [PATCH] rust: kernel: str: Implement Debug for CString MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230714-cstring-debug-v1-1-4e7c3018dd4f@asahilina.net> X-B4-Tracking: v=1; b=H4sIACQTsWQC/x3MQQqAIBBA0avErBPUAqOrRAvT0WZj4VQE4t2Tl m/xfwHGTMgwdwUyPsR0pAbVd+B2myIK8s2gpR6kUaNwfGVKUXjc7iiclVoFlNabCVpzZgz0/r9 lrfUD7QtijV8AAAA= To: Miguel Ojeda <ojeda@kernel.org>, Alex Gaynor <alex.gaynor@gmail.com>, Wedson Almeida Filho <wedsonaf@gmail.com>, Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, Benno Lossin <benno.lossin@proton.me> Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, Asahi Lina <lina@asahilina.net> X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689326377; l=768; i=lina@asahilina.net; s=20230221; h=from:subject:message-id; bh=xxvykvXcInvkp1nPJDBq3/LVlq3218mtzs6EEpgOuZM=; b=eVRCUCVHz0ocxsEaLFf7fiwn6ZrnWFVt5xgQ3D4WiHheqp897IEhKoC3DVZkJwIzRl/SZn53S StVIW12Q8yoBFVBQFV0Nvv6Vka2cl6ohbzDV152N+F9M7CFK9B5N658 X-Developer-Key: i=lina@asahilina.net; a=ed25519; pk=Qn8jZuOtR1m5GaiDfTrAoQ4NE1XoYVZ/wmt5YtXWFC4= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771389125165794027 X-GMAIL-MSGID: 1771389125165794027 |
Series |
rust: kernel: str: Implement Debug for CString
|
|
Commit Message
Asahi Lina
July 14, 2023, 9:19 a.m. UTC
Trivial implementation.
Signed-off-by: Asahi Lina <lina@asahilina.net>
---
rust/kernel/str.rs | 6 ++++++
1 file changed, 6 insertions(+)
---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230714-cstring-debug-ca021fe0ad78
Thank you,
~~ Lina
Comments
Asahi Lina <lina@asahilina.net> writes: > Trivial implementation. > > Signed-off-by: Asahi Lina <lina@asahilina.net> The commit message is a bit short, but the change itself looks fine. Reviewed-by: Alice Ryhl <aliceryhl@google.com>
On Fri, Jul 14, 2023 at 12:39 PM Asahi Lina <lina@asahilina.net> wrote: > > Trivial implementation. > > Signed-off-by: Asahi Lina <lina@asahilina.net> > --- > rust/kernel/str.rs | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs > index c9dd3bf59e34..a94e396d39e1 100644 > --- a/rust/kernel/str.rs > +++ b/rust/kernel/str.rs > @@ -606,6 +606,12 @@ fn try_from(cstr: &'a CStr) -> Result<CString, AllocError> { > } > } > > +impl fmt::Debug for CString { > + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { > + fmt::Debug::fmt(&**self, f) > + } > +} > + > /// A convenience alias for [`core::format_args`]. > #[macro_export] > macro_rules! fmt { > > --- > base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5 > change-id: 20230714-cstring-debug-ca021fe0ad78 > > Thank you, > ~~ Lina > Glad I wasn't the only one missing this, now I don't have to write the awkard `&*` anymore, as in: ``` pr_debug!("trying to open {:?}\n", &*filename); ``` Cheers, Ariel
On 14/07/2023 18.48, Alice Ryhl wrote: > Asahi Lina <lina@asahilina.net> writes: >> Trivial implementation. >> >> Signed-off-by: Asahi Lina <lina@asahilina.net> > > The commit message is a bit short, but the change itself looks fine. > > Reviewed-by: Alice Ryhl <aliceryhl@google.com> It's so trivial I just didn't know what else to write... suggestions welcome (for this or next time I have a patch like this) ^^ ~~ Lina
On 7/14/23 09:21, Asahi Lina wrote: > On 14/07/2023 18.48, Alice Ryhl wrote: >> Asahi Lina <lina@asahilina.net> writes: >>> Trivial implementation. >>> >>> Signed-off-by: Asahi Lina <lina@asahilina.net> >> >> The commit message is a bit short, but the change itself looks fine. >> >> Reviewed-by: Alice Ryhl <aliceryhl@google.com> > > It's so trivial I just didn't know what else to write... suggestions > welcome (for this or next time I have a patch like this) ^^ > > ~~ Lina > Just describe what it does, like "cast the `CStr` to an `&str` and call `fmt::Debug::fmt` with it". I'll add my Reviewed-by, so retain it in case it's asked to change the commit message. Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Asahi Lina <lina@asahilina.net> writes: > On 14/07/2023 18.48, Alice Ryhl wrote: >> Asahi Lina <lina@asahilina.net> writes: >>> Trivial implementation. >>> >>> Signed-off-by: Asahi Lina <lina@asahilina.net> >> >> The commit message is a bit short, but the change itself looks fine. >> >> Reviewed-by: Alice Ryhl <aliceryhl@google.com> > > It's so trivial I just didn't know what else to write... suggestions > welcome (for this or next time I have a patch like this) ^^ > > ~ Lina Adding some sort of motivation usually works quite well, e.g.: Make it possible to use a CString with the `pr_*` macros directly, that is, instead of pr_debug!("trying to open {:?}\n", &*filename); we can now write pr_debug!("trying to open {:?}\n", filename); Alice
On Fri, Jul 14, 2023 at 4:02 PM Alice Ryhl <aliceryhl@google.com> wrote: > > Adding some sort of motivation usually works quite well, e.g.: > > Make it possible to use a CString with the `pr_*` macros directly, that > is, instead of > > pr_debug!("trying to open {:?}\n", &*filename); > > we can now write > > pr_debug!("trying to open {:?}\n", filename); Indeed, this would be the most important bit, i.e. answering the "why?". The "what?" and the "how?" are pretty much explained by the title, but it is also fine giving more details (but if the implementation requires an explanation, then it is usually best to write an actual source code comment instead). Cheers, Miguel
On 14.07.23 11:19, Asahi Lina wrote: > Trivial implementation. > > Signed-off-by: Asahi Lina <lina@asahilina.net> With a better commit message you can add Reviewed-by: Benno Lossin <benno.lossin@proton.me>
On 23/07/14 05:01PM, Miguel Ojeda wrote: > On Fri, Jul 14, 2023 at 4:02 PM Alice Ryhl <aliceryhl@google.com> wrote: > > > > Adding some sort of motivation usually works quite well, e.g.: > > > > Make it possible to use a CString with the `pr_*` macros directly, that > > is, instead of > > > > pr_debug!("trying to open {:?}\n", &*filename); > > > > we can now write > > > > pr_debug!("trying to open {:?}\n", filename); > > Indeed, this would be the most important bit, i.e. answering the "why?". > > The "what?" and the "how?" are pretty much explained by the title, but > it is also fine giving more details (but if the implementation > requires an explanation, then it is usually best to write an actual > source code comment instead). > > Cheers, > Miguel Any follow-up on this? It sure would make my logging cleaner. Cheers, Ariel
On Wed, Oct 25, 2023 at 6:18 PM Ariel Miculas (amiculas) <amiculas@cisco.com> wrote: > > Any follow-up on this? It sure would make my logging cleaner. We were expecting a new version, but I can pick it up with e.g. the message that Alice suggested (i.e. marking it as modified by me). Cheers, Miguel
On Fri, Jul 14, 2023 at 11:19 AM Asahi Lina <lina@asahilina.net> wrote: > > Trivial implementation. > > Signed-off-by: Asahi Lina <lina@asahilina.net> Applied to `rust-next` with the commit message from Alice. Thanks everyone! Cheers, Miguel
diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index c9dd3bf59e34..a94e396d39e1 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -606,6 +606,12 @@ fn try_from(cstr: &'a CStr) -> Result<CString, AllocError> { } } +impl fmt::Debug for CString { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&**self, f) + } +} + /// A convenience alias for [`core::format_args`]. #[macro_export] macro_rules! fmt {