From e766abbc5191b444176c3b26713e7ac2f412b351 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 6 Jul 2026 14:44:27 +0200 Subject: drm/xe/i2c: use platform_device_set_fwnode() Ahead of reworking the reference counting logic for platform devices, encapsulate the assignment of the firmware node for dynamically allocated platform devices with the provided helper. Reviewed-by: Andy Shevchenko Signed-off-by: Bartosz Golaszewski Link: https://patch.msgid.link/20260706-pdev-fwnode-ref-v3-15-1ff028e33779@oss.qualcomm.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/xe/xe_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/gpu') diff --git a/drivers/gpu/drm/xe/xe_i2c.c b/drivers/gpu/drm/xe/xe_i2c.c index 706783863d07..af4ebd93ad8e 100644 --- a/drivers/gpu/drm/xe/xe_i2c.c +++ b/drivers/gpu/drm/xe/xe_i2c.c @@ -123,7 +123,7 @@ static int xe_i2c_register_adapter(struct xe_i2c *i2c) } pdev->dev.parent = i2c->drm_dev; - pdev->dev.fwnode = fwnode; + platform_device_set_fwnode(pdev, fwnode); i2c->adapter_node = fwnode; i2c->pdev = pdev; -- cgit v1.2.3 From 2c91f57e81a7ece7b0b83e93462558f661055963 Mon Sep 17 00:00:00 2001 From: Danilo Krummrich Date: Fri, 26 Jun 2026 20:36:08 +0200 Subject: rust: types: rename ForLt to CovariantForLt Rename ForLt to CovariantForLt to prepare for the introduction of a new ForLt base trait that does not require covariance. The existing ForLt trait requires covariance, which enables the safe cast_ref() method. This rename preserves the same semantics under a more precise name, making room for a weaker ForLt trait in a subsequent commit. No functional change. Reviewed-by: Alexandre Courbot Reviewed-by: Gary Guo Acked-by: Miguel Ojeda Link: https://patch.msgid.link/20260626183630.2585057-2-dakr@kernel.org Signed-off-by: Danilo Krummrich --- drivers/gpu/nova-core/driver.rs | 4 +-- rust/kernel/auxiliary.rs | 23 +++++++------- rust/kernel/types.rs | 2 +- rust/kernel/types/for_lt.rs | 57 ++++++++++++++++++----------------- rust/macros/for_lt.rs | 6 ++-- rust/macros/lib.rs | 11 +++---- samples/rust/rust_driver_auxiliary.rs | 8 ++--- 7 files changed, 56 insertions(+), 55 deletions(-) (limited to 'drivers/gpu') diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs index 5738d4ac521b..48380ac15f68 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -15,7 +15,7 @@ use kernel::{ Atomic, Relaxed, // }, - types::ForLt, + types::CovariantForLt, }; use crate::gpu::Gpu; @@ -29,7 +29,7 @@ pub(crate) struct NovaCore<'bound> { pub(crate) gpu: Gpu<'bound>, bar: pci::Bar<'bound, BAR0_SIZE>, #[allow(clippy::type_complexity)] - _reg: auxiliary::Registration<'bound, ForLt!(())>, + _reg: auxiliary::Registration<'bound, CovariantForLt!(())>, } pub(crate) struct NovaCoreDriver; diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs index c42928d5a239..40a0af74a8e5 100644 --- a/rust/kernel/auxiliary.rs +++ b/rust/kernel/auxiliary.rs @@ -20,7 +20,7 @@ use crate::{ }, prelude::*, types::{ - ForLt, + CovariantForLt, ForeignOwnable, Opaque, // }, @@ -272,16 +272,16 @@ impl Device { /// Returns a pinned reference to the registration data set by the registering (parent) driver. /// - /// `F` is the [`ForLt`](trait@ForLt) encoding of the data type. The returned + /// `F` is the [`CovariantForLt`](trait@CovariantForLt) encoding of the data type. The returned /// reference has its lifetime shortened from `'static` to `&self`'s borrow lifetime via - /// [`ForLt::cast_ref`]. + /// [`CovariantForLt::cast_ref`]. /// /// Returns [`EINVAL`] if `F` does not match the type used by the parent driver when calling /// [`Registration::new()`]. /// /// Returns [`ENOENT`] if no registration data has been set, e.g. when the device was /// registered by a C driver. - pub fn registration_data(&self) -> Result>> { + pub fn registration_data(&self) -> Result>> { // SAFETY: By the type invariant, `self.as_raw()` is a valid `struct auxiliary_device`. let ptr = unsafe { (*self.as_raw()).registration_data_rust }; if ptr.is_null() { @@ -399,8 +399,9 @@ struct RegistrationData { /// This type represents the registration of a [`struct auxiliary_device`]. When its parent device /// is unbound, the corresponding auxiliary device will be unregistered from the system. /// -/// The type parameter `F` is a [`ForLt`](trait@ForLt) encoding of the registration -/// data type. For non-lifetime-parameterized types, use [`ForLt!(T)`](macro@ForLt). +/// The type parameter `F` is a [`CovariantForLt`](trait@CovariantForLt) encoding of the +/// registration data type. For non-lifetime-parameterized types, use +/// [`CovariantForLt!(T)`](macro@CovariantForLt). /// The data can be accessed by the auxiliary driver through [`Device::registration_data()`]. /// /// # Invariants @@ -408,12 +409,12 @@ struct RegistrationData { /// `self.adev` always holds a valid pointer to an initialized and registered /// [`struct auxiliary_device`] whose `registration_data_rust` field points to a /// valid `Pin>>>`. -pub struct Registration<'a, F: ForLt + 'static> { +pub struct Registration<'a, F: CovariantForLt + 'static> { adev: NonNull, _phantom: PhantomData>, } -impl<'a, F: ForLt> Registration<'a, F> +impl<'a, F: CovariantForLt> Registration<'a, F> where for<'b> F::Of<'b>: Send + Sync, { @@ -525,7 +526,7 @@ where } } -impl Drop for Registration<'_, F> { +impl Drop for Registration<'_, F> { fn drop(&mut self) { // SAFETY: By the type invariant of `Self`, `self.adev.as_ptr()` is a valid registered // `struct auxiliary_device`. @@ -547,7 +548,7 @@ impl Drop for Registration<'_, F> { } // SAFETY: A `Registration` of a `struct auxiliary_device` can be released from any thread. -unsafe impl Send for Registration<'_, F> where for<'a> F::Of<'a>: Send {} +unsafe impl Send for Registration<'_, F> where for<'a> F::Of<'a>: Send {} // SAFETY: `Registration` does not expose any methods or fields that need synchronization. -unsafe impl Sync for Registration<'_, F> where for<'a> F::Of<'a>: Send {} +unsafe impl Sync for Registration<'_, F> where for<'a> F::Of<'a>: Send {} diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index ac316fd7b538..cbe6907042d3 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -13,7 +13,7 @@ use pin_init::{PinInit, Wrapper, Zeroable}; #[doc(hidden)] pub mod for_lt; -pub use for_lt::ForLt; +pub use for_lt::CovariantForLt; /// Used to transfer ownership to and from foreign (non-Rust) languages. /// diff --git a/rust/kernel/types/for_lt.rs b/rust/kernel/types/for_lt.rs index d44323c28e8d..a11f7509633c 100644 --- a/rust/kernel/types/for_lt.rs +++ b/rust/kernel/types/for_lt.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT -//! Provide implementation and test of the `ForLt` trait and macro. +//! Provide implementation and test of the `CovariantForLt` trait and macro. //! -//! This module is hidden and user should just use `ForLt!` directly. +//! This module is hidden and user should just use `CovariantForLt!` directly. use core::marker::PhantomData; @@ -15,38 +15,39 @@ use core::marker::PhantomData; /// /// # Macro /// -/// It is not recommended to implement this trait directly. `ForLt!` macro is provided to obtain a -/// type that implements this trait. +/// It is not recommended to implement this trait directly. `CovariantForLt!` macro is provided to +/// obtain a type that implements this trait. /// /// The full syntax is /// /// ``` -/// # use kernel::types::ForLt; -/// # fn expect_lt() {} +/// # use kernel::types::CovariantForLt; +/// # fn expect_lt() {} /// # struct TypeThatUse<'a>(&'a ()); /// # expect_lt::< -/// ForLt!(for<'a> TypeThatUse<'a>) +/// CovariantForLt!(for<'a> TypeThatUse<'a>) /// # >(); /// ``` /// -/// which gives a type so that ` TypeThatUse<'a>) as ForLt>::Of<'b>` +/// which gives a type so that +/// ` TypeThatUse<'a>) as CovariantForLt>::Of<'b>` /// is `TypeThatUse<'b>`. /// /// You may also use a short-hand syntax which works similar to lifetime elision. /// The macro also accepts types that do not involve a lifetime at all. /// /// ``` -/// # use kernel::types::ForLt; -/// # fn expect_lt() {} +/// # use kernel::types::CovariantForLt; +/// # fn expect_lt() {} /// # struct TypeThatUse<'a>(&'a ()); /// # expect_lt::< -/// ForLt!(TypeThatUse<'_>) // Equivalent to `ForLt!(for<'a> TypeThatUse<'a>)`. +/// CovariantForLt!(TypeThatUse<'_>) // Equivalent to `CovariantForLt!(for<'a> TypeThatUse<'a>)`. /// # >(); /// # expect_lt::< -/// ForLt!(&u32) // Equivalent to `ForLt!(for<'a> &'a u32)`. +/// CovariantForLt!(&u32) // Equivalent to `CovariantForLt!(for<'a> &'a u32)`. /// # >(); /// # expect_lt::< -/// ForLt!(u32) // Equivalent to `ForLt!(for<'a> u32)`. +/// CovariantForLt!(u32) // Equivalent to `CovariantForLt!(for<'a> u32)`. /// # >(); /// ``` /// @@ -55,10 +56,10 @@ use core::marker::PhantomData; /// it. /// /// ```ignore,compile_fail -/// # use kernel::types::ForLt; -/// # fn expect_lt() {} +/// # use kernel::types::CovariantForLt; +/// # fn expect_lt() {} /// # expect_lt::< -/// ForLt!(fn(&u32)) // Contravariant, will fail compilation. +/// CovariantForLt!(fn(&u32)) // Contravariant, will fail compilation. /// # >(); /// ``` /// @@ -67,23 +68,23 @@ use core::marker::PhantomData; /// the generic parameter but is in a separate item. /// /// ``` -/// # use kernel::types::ForLt; -/// fn expect_lt() {} +/// # use kernel::types::CovariantForLt; +/// fn expect_lt() {} /// # #[allow(clippy::unnecessary_safety_comment, reason = "false positive")] /// fn generic_fn() { /// // Syntactically proven by the macro -/// expect_lt::(); +/// expect_lt::(); /// // Syntactically proven by the macro -/// expect_lt::)>(); +/// expect_lt::)>(); /// // Cannot be syntactically proven, need to check covariance of `KBox` -/// // expect_lt::)>(); +/// // expect_lt::)>(); /// } /// ``` /// /// # Safety /// /// `Self::Of<'a>` must be covariant over the lifetime `'a`. -pub unsafe trait ForLt { +pub unsafe trait CovariantForLt { /// The type parameterized by the lifetime. type Of<'a>: 'a; @@ -94,11 +95,11 @@ pub unsafe trait ForLt { unsafe { core::mem::transmute(long) } } } -pub use macros::ForLt; +pub use macros::CovariantForLt; /// This is intended to be an "unsafe-to-refer-to" type. /// -/// Must only be used by the `ForLt!` macro. +/// Must only be used by the `CovariantForLt!` macro. /// /// `T` is the magic `dyn for<'a> WithLt<'a, TypeThatUse<'a>>` generated by macro. /// @@ -109,14 +110,14 @@ pub use macros::ForLt; #[doc(hidden)] pub struct UnsafeForLtImpl(PhantomData<(WF, T)>); -// This is a helper trait for implementation `ForLt` to be able to use HRTB. +// This is a helper trait for implementation `CovariantForLt` to be able to use HRTB. #[doc(hidden)] pub trait WithLt<'a> { type Of: 'a; } -// SAFETY: In `ForLt!` macro, a covariance proof is generated when naming `UnsafeForLtImpl` -// and it will fail to evaluate if the type is not covariant. -unsafe impl WithLt<'a>, WF> ForLt for UnsafeForLtImpl { +// SAFETY: In `CovariantForLt!` macro, a covariance proof is generated when naming +// `UnsafeForLtImpl` and it will fail to evaluate if the type is not covariant. +unsafe impl WithLt<'a>, WF> CovariantForLt for UnsafeForLtImpl { type Of<'a> = >::Of; } diff --git a/rust/macros/for_lt.rs b/rust/macros/for_lt.rs index 364d4113cd10..9487a9352f1c 100644 --- a/rust/macros/for_lt.rs +++ b/rust/macros/for_lt.rs @@ -154,8 +154,8 @@ impl<'a> Prover<'a> { // Note that if we encounter `&'other_lt T`, then we still need to make sure the type // is wellformed if `T` involves `&'lt`, so we defer to the compiler. // - // This is to block cases like `ForLt!(for<'a> &'static &'a u32)`, as the presence of - // the type implies `'a: 'static` but this is unsound. + // This is to block cases like `CovariantForLt!(for<'a> &'static &'a u32)`, as the + // presence of the type implies `'a: 'static` but this is unsound. Type::Reference(ty) if ty.mutability.is_none() && ty.lifetime.as_ref() == Some(self.0) => { @@ -176,7 +176,7 @@ impl<'a> Prover<'a> { } } -pub(crate) fn for_lt(input: HigherRankedType) -> TokenStream { +pub(crate) fn covariant_for_lt(input: HigherRankedType) -> TokenStream { let (ty, lifetime) = match input { HigherRankedType::Explicit { lifetime, ty, .. } => (ty, lifetime), HigherRankedType::Implicit { ty } => { diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs index 4a48fabbc268..2167cb270928 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -491,14 +491,13 @@ pub fn kunit_tests(attr: TokenStream, input: TokenStream) -> TokenStream { .into() } -/// Obtain a type that implements [`ForLt`] for the given higher-ranked type. +/// Obtain a type that implements [`CovariantForLt`] for the given higher-ranked type. /// -/// Please refer to the documentation of the [`ForLt`] trait. +/// Please refer to the documentation of the [`CovariantForLt`] trait. /// -/// [`ForLt`]: trait.ForLt.html +/// [`CovariantForLt`]: trait.CovariantForLt.html #[proc_macro] -// The macro shares the name with the trait. #[allow(non_snake_case)] -pub fn ForLt(input: TokenStream) -> TokenStream { - for_lt::for_lt(parse_macro_input!(input)).into() +pub fn CovariantForLt(input: TokenStream) -> TokenStream { + for_lt::covariant_for_lt(parse_macro_input!(input)).into() } diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs index 2c1351040e45..92ee6a6d348e 100644 --- a/samples/rust/rust_driver_auxiliary.rs +++ b/samples/rust/rust_driver_auxiliary.rs @@ -13,7 +13,7 @@ use kernel::{ driver, pci, prelude::*, - types::ForLt, + types::CovariantForLt, InPlaceModule, // }; @@ -60,8 +60,8 @@ struct ParentDriver; #[allow(clippy::type_complexity)] struct ParentData<'bound> { - _reg0: auxiliary::Registration<'bound, ForLt!(Data<'_>)>, - _reg1: auxiliary::Registration<'bound, ForLt!(Data<'_>)>, + _reg0: auxiliary::Registration<'bound, CovariantForLt!(Data<'_>)>, + _reg1: auxiliary::Registration<'bound, CovariantForLt!(Data<'_>)>, } kernel::pci_device_table!( @@ -115,7 +115,7 @@ impl pci::Driver for ParentDriver { impl ParentDriver { fn connect(adev: &auxiliary::Device) -> Result { - let data = adev.registration_data::)>()?; + let data = adev.registration_data::)>()?; let pdev = data.parent; dev_info!( -- cgit v1.2.3