remove TryFrom<&Device> implementation for pci and platform
Subsystems (3)
cover remove TryFrom<&Device> implementation for pci and platform
Hello,
This patch series removes TryFrom<&Device<Ctx>> implementations for pci and platform's Device struct.
To make sure that there were no remaining users, I checked for usages of the try_from method and the structs implementing TryFrom using rust analyzer, activated the modules that were using the structs, removed the implementation and compiled the kernel (did not trust entirely in rust analyzer because it does not find usages that depend on this implementation like the try_into() in fact, the last usage of the trait was a try_into() in pci).
I did what I described above from the most recent changes (rust-next, linux-next, drm-rust-next) down to the introduction of the implementation, stopping in all major versions (7.3-rc7 to 6.19) to find the last usage and mark the commit in the Fixes: tag. I found no usages for the platform implementation.
If applied to current rust-next, commit 7c306f00835a ("rust: zerocopy:
update to v0.8.62"), nova driver will fail to build, drm-rust-next and linux-next are ok.
This series, along with the i2c patch [1], closes:
https://github.com/Rust-for-Linux/linux/issues/1264
I made this a series because both TryFrom implementations were introduced in a series:
https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/rust-for-linux/[email protected]/T/#u
Best regards,
Nicolás
Nicolás Antinori (2):
rust: pci: remove TryFrom<&Device> implementation for &pci::Device
rust: platform: remove TryFrom<&Device> implementation for
&platform::Device
rust/kernel/pci.rs | 21 --------------------- rust/kernel/platform.rs | 21 --------------------- 2 files changed, 42 deletions(-)
--
2.47.3
PATCH 1/2 rust: pci: remove TryFrom<&Device> implementation for &pci::Device
Remove the TryFrom<&device::Device<Ctx>> implementation for &Device<Ctx> since it has no remaining users.
--- rust/kernel/pci.rs | 21 --------------------- 1 file changed, 21 deletions(-)
rust/kernel/pci.rs +0 -21
@@ -6,7 +6,6 @@use crate ::{ bindings, - container_of, device, device_id::{RawDeviceId ,
@@ -535,26 +534,6 @@ fn as_ref(&self) -> &device::Device<Ctx> { } } -impl <Ctx : device::DeviceContext >TryFrom <&device::Device <Ctx >>for &Device <Ctx > { -type Error = kernel::error::Error ; - -fn try_from (dev: &device::Device <Ctx >) ->Result <Self ,Self ::Error > { -// SAFETY: By the type invariant of `Device`, `dev.as_raw()` is a valid pointer to a -// `struct device`. -if !unsafe { bindings::dev_is_pci (dev.as_raw ()) } { -return Err (EINVAL ); - } - -// SAFETY: We've just verified that the bus type of `dev` equals `bindings::pci_bus_type`, -// hence `dev` must be embedded in a valid `struct pci_dev` as guaranteed by the -// corresponding C code. -let pdev =unsafe {container_of! (dev.as_raw (), bindings::pci_dev, dev) }; - -// SAFETY: `pdev` is a valid pointer to a `struct pci_dev`. -Ok (unsafe { &*pdev.cast () }) - } -} -// SAFETY: A `Device` is always reference-counted and can be released from any thread. unsafe impl Send for Device {}
--
2.47.3
PATCH 2/2 rust: platform: remove TryFrom<&Device> implementation for &platform::Device
In reply to Nicolás AntinoriRemove the TryFrom<&device::Device<Ctx>> implementation for &Device<Ctx> since it has had no users since its introduction.
--- rust/kernel/platform.rs | 21 --------------------- 1 file changed, 21 deletions(-)
rust/kernel/platform.rs +0 -21
@@ -7,7 +7,6 @@use crate ::{ acpi, bindings, - container_of, device::{ self,Bound ,//
@@ -557,26 +556,6 @@ fn as_ref(&self) -> &device::Device<Ctx> { } } -impl <Ctx : device::DeviceContext >TryFrom <&device::Device <Ctx >>for &Device <Ctx > { -type Error = kernel::error::Error ; - -fn try_from (dev: &device::Device <Ctx >) ->Result <Self ,Self ::Error > { -// SAFETY: By the type invariant of `Device`, `dev.as_raw()` is a valid pointer to a -// `struct device`. -if !unsafe { bindings::dev_is_platform (dev.as_raw ()) } { -return Err (EINVAL ); - } - -// SAFETY: We've just verified that the bus type of `dev` equals -// `bindings::platform_bus_type`, hence `dev` must be embedded in a valid -// `struct platform_device` as guaranteed by the corresponding C code. -let pdev =unsafe {container_of! (dev.as_raw (), bindings::platform_device, dev) }; - -// SAFETY: `pdev` is a valid pointer to a `struct platform_device`. -Ok (unsafe { &*pdev.cast () }) - } -} -// SAFETY: A `Device` is always reference-counted and can be released from any thread. unsafe impl Send for Device {}
--
2.47.3
Re: [PATCH 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device
In reply to Nicolás AntinoriHello,
Quoted 7 lines · Nicolás Antinori
Remove the
TryFrom<&device::Device<Ctx>>implementation for&Device<Ctx>since it has no remaining users.Fixes 7edc491f6fca ("drm: nova: Use nova-core to read VRAM_BAR_SIZE parameter")Reported-by Georgios Androutsopoulos <[email protected]>Signed-off-by Nicolás Antinori <[email protected]>
I got two reviews from Sashiko [1]
Quoted 8 lines
[Severity: Low]
Does removing this TryFrom implementation break the build whenCONFIG_DRM_NOVAis enabled?The commit message references commit
7edc491f6fca("drm: nova: Use nova-core to readVRAM_BAR_SIZEparameter"), which is not present in this baseline branch. Without that commit applied first,File::get_param()indrivers/gpu/drm/nova/file.rsstill relies on this conversion:
This is true for the rust-next branch in the R4L tree, but the named commit is present in linux-next [2] and drm-rust-next [3], and the patch application and compilation were tested in those too.
I am pretty sure the patches were created based on the master branch of linux-next tree (because of the discussion in [4]).
Quoted 4 lines
[Severity: Low]
SinceTryFrom::try_from()was the only caller ofbindings::dev_is_pci(), shouldrust_helper_dev_is_pci()inrust/helpers/pci.calso be removed along with it?
I didn't see this. I apologize for the oversight. I can send a separate patch or a v2 of this patch alone, since the patches of the series are related but can be applied independently.
Best regards,
Nicolás
[1] https://sashiko.dev/#/patchset/[email protected]?part=1
[2] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=7edc491f6fca8e22f51e37a16d74914cd959274d
[3] https://gitlab.freedesktop.org/drm/rust/kernel/-/commit/7edc491f6fca8e22f51e37a16d74914cd959274d
[4] https://github.com/Rust-for-Linux/linux/issues/1264#issuecomment-6194695910