From: Danilo Krummrich <dakr@kernel.org>
To: Tamir Duberstein <tamird@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Matthew Wilcox" <willy@infradead.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Rob Herring (Arm)" <robh@kernel.org>,
"Maíra Canal" <mcanal@igalia.com>,
"Asahi Lina" <lina@asahilina.net>,
rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v16 1/4] rust: remove redundant `as _` casts
Date: Mon, 17 Feb 2025 12:06:29 +0100 [thread overview]
Message-ID: <Z7MYNQgo28sr_4RS@cassiopeiae> (raw)
In-Reply-To: <20250207-rust-xarray-bindings-v16-1-256b0cf936bd@gmail.com>
On Fri, Feb 07, 2025 at 08:58:24AM -0500, Tamir Duberstein wrote:
> Remove redundant casts added in commit 1bd8b6b2c5d3 ("rust: pci: add
> basic PCI device / driver abstractions") and commit 683a63befc73 ("rust:
> platform: add basic platform device / driver abstractions")
I thought of doing it the other way around: Do only the *required* changes in
commit "rust: types: add `ForeignOwnable::PointedTo`", i.e. no need to touch
this code at all. And then switch to cast() in a subsequent patch.
This way you don't need to remove (previously unnecessary) casts and then add
them back in.
>
> While I'm churning this line, move the `.into_foreign()` call to its own
> statement to avoid churn in the next commit which adds a `.cast()` call.
>
> Fixes: 1bd8b6b2c5d3 ("rust: pci: add basic PCI device / driver abstractions")
> Fixes: 683a63befc73 ("rust: platform: add basic platform device / driver abstractions")
No, at the time those casts were indeed necessary, because the types differed in
mutability.
"A Fixes: tag indicates that the patch fixes an issue in a previous commit." [1]
Even if the cast was unnecessary in the first place, it is at least questionable
to me whether this falls under "fixing an issue".
[1] https://docs.kernel.org/process/submitting-patches.html#reviewer-s-statement-of-oversight
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> ---
> rust/kernel/pci.rs | 3 ++-
> rust/kernel/platform.rs | 3 ++-
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index 4c98b5b9aa1e..6c3bc14b42ad 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -72,10 +72,11 @@ extern "C" fn probe_callback(
>
> match T::probe(&mut pdev, info) {
> Ok(data) => {
> + let data = data.into_foreign();
> // Let the `struct pci_dev` own a reference of the driver's private data.
> // SAFETY: By the type invariant `pdev.as_raw` returns a valid pointer to a
> // `struct pci_dev`.
> - unsafe { bindings::pci_set_drvdata(pdev.as_raw(), data.into_foreign() as _) };
> + unsafe { bindings::pci_set_drvdata(pdev.as_raw(), data) };
Please do not factor this out, it is unnecessary for what you want to accomplish
with your commit.
> }
> Err(err) => return Error::to_errno(err),
> }
> diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
> index 50e6b0421813..dea104563fa9 100644
> --- a/rust/kernel/platform.rs
> +++ b/rust/kernel/platform.rs
> @@ -63,10 +63,11 @@ extern "C" fn probe_callback(pdev: *mut bindings::platform_device) -> kernel::ff
> let info = <Self as driver::Adapter>::id_info(pdev.as_ref());
> match T::probe(&mut pdev, info) {
> Ok(data) => {
> + let data = data.into_foreign();
> // Let the `struct platform_device` own a reference of the driver's private data.
> // SAFETY: By the type invariant `pdev.as_raw` returns a valid pointer to a
> // `struct platform_device`.
> - unsafe { bindings::platform_set_drvdata(pdev.as_raw(), data.into_foreign() as _) };
> + unsafe { bindings::platform_set_drvdata(pdev.as_raw(), data) };
> }
> Err(err) => return Error::to_errno(err),
> }
>
> --
> 2.48.1
>
next prev parent reply other threads:[~2025-02-17 11:06 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 13:58 [PATCH v16 0/4] rust: xarray: Add a minimal abstraction for XArray Tamir Duberstein
2025-02-07 13:58 ` [PATCH v16 1/4] rust: remove redundant `as _` casts Tamir Duberstein
2025-02-17 11:06 ` Danilo Krummrich [this message]
2025-02-07 13:58 ` [PATCH v16 2/4] rust: types: add `ForeignOwnable::PointedTo` Tamir Duberstein
2025-02-17 1:39 ` Benno Lossin
2025-02-17 1:58 ` Tamir Duberstein
2025-02-17 12:12 ` Danilo Krummrich
2025-02-17 14:02 ` Tamir Duberstein
2025-02-17 14:15 ` Danilo Krummrich
2025-02-17 14:21 ` Tamir Duberstein
2025-02-17 14:37 ` Danilo Krummrich
2025-02-17 14:47 ` Tamir Duberstein
2025-02-17 14:51 ` Danilo Krummrich
2025-02-17 15:50 ` Tamir Duberstein
2025-02-17 16:35 ` Danilo Krummrich
2025-02-17 17:03 ` Miguel Ojeda
2025-02-17 17:03 ` Miguel Ojeda
2025-02-17 17:03 ` Miguel Ojeda
2025-02-17 17:11 ` Tamir Duberstein
2025-02-17 17:24 ` Miguel Ojeda
2025-02-17 17:36 ` Miguel Ojeda
2025-02-17 17:43 ` Tamir Duberstein
2025-02-17 18:12 ` Miguel Ojeda
2025-02-17 18:24 ` Tamir Duberstein
2025-02-18 8:59 ` Andreas Hindborg
2025-02-07 13:58 ` [PATCH v16 3/4] rust: xarray: Add an abstraction for XArray Tamir Duberstein
2025-02-17 11:35 ` Danilo Krummrich
2025-02-17 13:43 ` Tamir Duberstein
2025-02-17 13:57 ` Danilo Krummrich
2025-02-07 13:58 ` [PATCH v16 4/4] MAINTAINERS: add entry for Rust XArray API Tamir Duberstein
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=Z7MYNQgo28sr_4RS@cassiopeiae \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=lina@asahilina.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mcanal@igalia.com \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@gmail.com \
--cc=tmgross@umich.edu \
--cc=willy@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).