Skip to contentSkip to conversation

rust: leds: add led classdev abstractions

PATCH Superseded Markus Probst 2 participants 4 messages Oct 10, 2025 – Oct 12, 2025

Subsystems (3)

v3 of 28 Superseded Latest is v28 →

lore
Share & tools
lore
#0 lore raw

v3 cover rust: leds: add led classdev abstractions

This patch series has previously been contained in
https://lore.kernel.org/rust-for-linux/[email protected]/T/#t
which added a rust written led driver for a microcontroller via i2c.

As the reading and writing to the i2c client via the register! macro has not been implemented yet [1], the patch series will only contain the additional abstractions required.

[1] https://lore.kernel.org/rust-for-linux/[email protected]/

The following changes were made:
* add basic Pin<Vec<T, A>> abstractions, that allow to initialize PinInit items with the guarantee that these will never be moved.

* add basic led classdev abstractions to register and unregister leds

Changes since v2:
* return Devres on led::Device creation
* replace KBox<T> with T in struct definition
* increment and decrement reference-count of fwnode
* make a device parent mandatory for led classdev creation
* rename led::Handler to led::LedOps
* add optional brightness_get function to led::LedOps
* use #[vtable] instead of const BLINK: bool
* use Opaque::cast_from instead of casting a pointer
* improve documentation
* improve support for older rust versions
* use &Device<Bound> for parent

Changes since v1:
* fixed typos noticed by Onur Özkan

Markus Probst (2):
rust: add basic Pin<Vec<T, A>> abstractions
rust: leds: add basic led classdev abstractions

 rust/kernel/alloc.rs      |   1 +
 rust/kernel/alloc/kvec.rs |  86 ++++++++++
 rust/kernel/led.rs        | 332 ++++++++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs        |   1 +
 rust/kernel/prelude.rs    |   2 +-
 5 files changed, 421 insertions(+), 1 deletion(-)
 create mode 100644 rust/kernel/led.rs
Signature · 1 line
2.49.1
#1 lore raw

PATCH v3 1/2 rust: add basic Pin<Vec<T, A>> abstractions

Implement core Pin<Vec<T, A>> abstractions, including
* Vec::pin and Vec::into_pin for constructing a Pin<Vec<T, A>>. If T does not implement Unpin, its values will never be moved.
* an extension for Pin<Vec<T, A>> allowing PinInit to be initialied on a Pin<Vec>, as well as truncating and popping values from the Vec

---
 rust/kernel/alloc.rs      |  1 +
 rust/kernel/alloc/kvec.rs | 86 +++++++++++++++++++++++++++++++++++++++
 rust/kernel/prelude.rs    |  2 +-
 3 files changed, 88 insertions(+), 1 deletion(-)
rust/kernel/alloc.rs +1 -0
index a2c49e5494d3..d1a1200fc1bd 100644
@@ -22,6 +22,7 @@
 pub use self::kvec::IntoIter;
 pub use self::kvec::KVVec;
 pub use self::kvec::KVec;
+pub use self::kvec::PinnedVecExt;
 pub use self::kvec::VVec;
 pub use self::kvec::Vec;
 
rust/kernel/alloc/kvec.rs +86 -0

115 lines not on this page · raw message

rust/kernel/prelude.rs +1 -1
index 25fe97aafd02..7179e2ca2a14 100644
@@ -19,7 +19,7 @@
     c_ushort, c_void,
 };
 
-pub use crate::alloc::{flags::*, Box, KBox, KVBox, KVVec, KVec, VBox, VVec, Vec};
+pub use crate::alloc::{flags::*, Box, KBox, KVBox, KVVec, KVec, PinnedVecExt, VBox, VVec, Vec};
 
 #[doc(no_inline)]
 pub use macros::{export, kunit_tests, module, vtable};
Signature · 1 line
2.49.1
#2 lore raw

PATCH v3 2/2 rust: leds: add basic led classdev abstractions

In reply to Markus Probst

Implement the core abstractions needed for led class devices, including:

* led::LedOps - the trait for handling leds, including brightness_set, brightness_get and blink_set

* led::InitData - data set for the led class device

* led::Device - a safe wrapper around led_classdev

---
 rust/kernel/led.rs | 332 +++++++++++++++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs |   1 +
 2 files changed, 333 insertions(+)
 create mode 100644 rust/kernel/led.rs
rust/kernel/led.rs new file +332 -0
new file mode 100644
index 000000000000..feac509bda3f
@@ -0,0 +1,332 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Abstractions for the leds driver model.
+//!
+//! C header: [`include/linux/leds.h`](srctree/include/linux/leds.h)
+
+use core::{marker::PhantomData, pin::Pin, ptr::NonNull};
+
+use pin_init::{pin_data, pinned_drop, PinInit};
+
+use crate::{
+    build_error, container_of,
+    device::{self, property::FwNode, Bound},
+    devres::Devres,
+    error::{from_result, to_result, Error, Result, VTABLE_DEFAULT_ERROR},
+    macros::vtable,
+    str::CStr,
+    try_pin_init,
+    types::{ARef, Opaque},
+};
+
+/// The led class device representation.
+///
+/// This structure represents the Rust abstraction for a C `struct led_classdev`.
+#[pin_data(PinnedDrop)]
+pub struct Device<T: LedOps> {
+    ops: T,
+    #[pin]
+    classdev: Opaque<bindings::led_classdev>,
+}
+
+/// The led init data representation.
+///
+/// This structure represents the Rust abstraction for a C `struct led_init_data`.
+#[derive(Default)]
+pub struct InitData<'a> {
+    fwnode: Option<&'a FwNode>,
+    default_label: Option<&'a CStr>,
+    devicename: Option<&'a CStr>,
+    devname_mandatory: bool,
+}
+
+impl InitData<'static> {
+    /// Creates a new [`InitData`]
+    pub fn new() -> Self {
+        Self::default()
+    }
+}
+
+impl<'a> InitData<'a> {
+    /// Sets the firmware node
+    pub fn fwnode<'b, 'c>(self, fwnode: &'b FwNode) -> InitData<'c>
+    where
+        'a: 'c,
+        'b: 'c,
+    {
+        InitData {
+            fwnode: Some(fwnode),
+            ..self
+        }
+    }
+
+    /// Sets a default label
+    pub fn default_label<'b, 'c>(self, label: &'b CStr) -> InitData<'c>
+    where
+        'a: 'c,
+        'b: 'c,
+    {
+        InitData {
+            default_label: Some(label),
+            ..self
+        }
+    }
+
+    /// Sets the device name
+    pub fn devicename<'b, 'c>(self, devicename: &'b CStr) -> InitData<'c>
+    where
+        'a: 'c,
+        'b: 'c,
+    {
+        InitData {
+            devicename: Some(devicename),
+            ..self
+        }
+    }
+
+    /// Sets if a device name is mandatory
+    pub fn devicename_mandatory(self, mandatory: bool) -> Self {
+        Self {
+            devname_mandatory: mandatory,
+
+            ..self
+        }
+    }
+}
+
+/// Trait defining the operations for a LED driver.
+///
+/// # Examples
+///
+///```
+/// # use kernel::{c_str, led, alloc::KBox, error::Result, macros::vtable};
+/// # use core::pin::Pin;
+///
+/// struct MyLedOps;
+///
+///
+/// #[vtable]
+/// impl led::LedOps for MyLedOps {
+///     const BLOCKING = false;
+///     const MAX_BRIGHTNESS = 255;
+///
+///     fn brightness_set(&self, _brightness: u32) -> Result<()> {
+///         // Set the brightness for the led here
+///         Ok(())
+///     }
+/// }
+///
+/// fn register_my_led() -> Result<Pin<KBox<led::Device>>> {
+///     KBox::pin_init(led::Device::new(
+///         None,
+///         None,
+///         led::InitData::new()
+///             .default_label(c_str!("my_led")),
+///         MyLedOps,
+///     ))
+/// }
+///```
+/// Led drivers must implement this trait in order to register and handle a [`Device`].
+#[vtable]
+pub trait LedOps: Send + 'static + Sized {
+    /// If set true, [`LedOps::brightness_set`] and [`LedOps::blink_set`] must not sleep
+    /// and perform the operation immediately.
+    const BLOCKING: bool;
+    /// The max brightness level
+    const MAX_BRIGHTNESS: u32;
+
+    /// Sets the brightness level.
+    ///
+    /// See also [`LedOps::BLOCKING`]
+    fn brightness_set(&self, brightness: u32) -> Result<()>;
+
+    /// Gets the current brightness level.
+    fn brightness_get(&self) -> u32 {
+        build_error!(VTABLE_DEFAULT_ERROR)
+    }
+
+    /// Activates hardware accelerated blinking.
+    ///
+    /// delays are in milliseconds. If both are zero, a sensible default should be chosen.
+    /// The caller should adjust the timings in that case and if it can't match the values
+    /// specified exactly. Setting the brightness to 0 will disable the hardware accelerated
+    /// blinking.
+    ///
+    /// See also [`LedOps::BLOCKING`]
+    fn blink_set(&self, _delay_on: &mut usize, _delay_off: &mut usize) -> Result<()> {
+        build_error!(VTABLE_DEFAULT_ERROR)
+    }
+}
+
+// SAFETY: A `led::Device` can be unregistered from any thread.
+unsafe impl<T: LedOps + Send> Send for Device<T> {}
+
+// SAFETY: `led::Device` can be shared among threads because all methods of `led::Device`
+// are thread safe.
+unsafe impl<T: LedOps + Sync> Sync for Device<T> {}
+
+impl<T: LedOps> Device<T> {
+    /// Registers a new led classdev.
+    ///
+    /// The [`Device`] will be unregistered on drop.
+    pub fn new<'a>(
+        parent: &'a device::Device<Bound>,
+        init_data: InitData<'a>,
+        ops: T,
+    ) -> impl PinInit<Devres<Self>, Error> + 'a {
+        Devres::new(
+            parent,
+            try_pin_init!(Self {
+                ops,
+                classdev <- Opaque::try_ffi_init(|ptr: *mut bindings::led_classdev| {
+                    // SAFETY: `try_ffi_init` guarantees that `ptr` is valid for write.
+                    // `led_classdev` gets fully initialized in-place by
+                    // `led_classdev_register_ext` including `mutex` and `list_head`.
+                    unsafe { ptr.write(bindings::led_classdev {
+                        max_brightness: T::MAX_BRIGHTNESS,
+                        brightness_set: T::BLOCKING
+                            .then_some(Adapter::<T>::brightness_set_callback),
+                        brightness_set_blocking: (!T::BLOCKING)
+                            .then_some(Adapter::<T>::brightness_set_blocking_callback),
+                        brightness_get: T::HAS_BRIGHTNESS_GET
+                            .then_some(Adapter::<T>::brightness_get_callback),
+                        blink_set: T::HAS_BLINK_SET
+                            .then_some(Adapter::<T>::blink_set_callback),
+                        .. bindings::led_classdev::default()
+                    }) };
+
+                    let fwnode = init_data.fwnode.map(ARef::from);
+
+                    let mut init_data = bindings::led_init_data {
+                        fwnode: fwnode.as_ref()
+                            .map_or(core::ptr::null_mut(), |fwnode| fwnode.as_raw()),
+                        default_label: init_data.default_label
+                                                .map_or(core::ptr::null(), CStr::as_char_ptr),
+                        devicename: init_data.devicename
+                            .map_or(core::ptr::null(), CStr::as_char_ptr),
+                        devname_mandatory: init_data.devname_mandatory,
+                    };
+
+                    // SAFETY:
+                    // - `parent.as_raw()` is guaranteed to be a pointer to a valid `device`
+                    //    or a null pointer.
+                    // - `ptr` is guaranteed to be a pointer to an initialized `led_classdev`.
+                    to_result(unsafe {
+                        bindings::led_classdev_register_ext(parent.as_raw(), ptr, &mut init_data)
+                    })?;
+
+                    core::mem::forget(fwnode); // keep the reference count incremented
+
+                    Ok::<_, Error>(())
+                }),
+            }),
+        )
+    }
+
+    /// # Safety
+    /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a
+    /// `led::Device`.
+    unsafe fn from_raw<'a>(led_cdev: *mut bindings::led_classdev) -> &'a Self {
+        // SAFETY: The function's contract guarantees that `led_cdev` points to a `led_classdev`
+        // field embedded within a valid `led::Device`. `container_of!` can therefore
+        // safely calculate the address of the containing struct.
+        unsafe { &*container_of!(Opaque::cast_from(led_cdev), Self, classdev) }
+    }
+}
+
+struct Adapter<T: LedOps> {
+    _p: PhantomData<T>,
+}
+
+impl<T: LedOps> Adapter<T> {
+    /// # Safety
+    /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a
+    /// `led::Device`.
+    /// This function is called on setting the brightness of a led.
+    unsafe extern "C" fn brightness_set_callback(
+        led_cdev: *mut bindings::led_classdev,
+        brightness: u32,
+    ) {
+        // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a
+        // `led_classdev` embedded within a `led::Device`.
+        let _ = unsafe { Device::<T>::from_raw(led_cdev) }
+            .ops
+            .brightness_set(brightness);
+    }
+
+    /// # Safety
+    /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a
+    /// `led::Device`.
+    /// This function is called on setting the brightness of a led immediately.
+    unsafe extern "C" fn brightness_set_blocking_callback(
+        led_cdev: *mut bindings::led_classdev,
+        brightness: u32,
+    ) -> i32 {
+        from_result(|| {
+            // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a
+            // `led_classdev` embedded within a `led::Device`.
+            unsafe { Device::<T>::from_raw(led_cdev) }
+                .ops
+                .brightness_set(brightness)?;
+            Ok(0)
+        })
+    }
+
+    /// # Safety
+    /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a
+    /// `led::Device`.
+    /// This function is called on getting the brightness of a led.
+    unsafe extern "C" fn brightness_get_callback(led_cdev: *mut bindings::led_classdev) -> u32 {
+        // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a
+        // `led_classdev` embedded within a `led::Device`.
+        unsafe { Device::<T>::from_raw(led_cdev) }
+            .ops
+            .brightness_get()
+    }
+
+    /// # Safety
+    /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a
+    /// `led::Device`.
+    /// `delay_on` and `delay_off` must be valid pointers to `usize` and have
+    /// exclusive access for the period of this function.
+    /// This function is called on enabling hardware accelerated blinking.
+    unsafe extern "C" fn blink_set_callback(
+        led_cdev: *mut bindings::led_classdev,
+        delay_on: *mut usize,
+        delay_off: *mut usize,
+    ) -> i32 {
+        from_result(|| {
+            // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a
+            // `led_classdev` embedded within a `led::Device`.
+            unsafe { Device::<T>::from_raw(led_cdev) }.ops.blink_set(
+                // SAFETY: The function's contract guarantees that `delay_on` points to a `usize`
+                // and is exclusive for the period of this function.
+                unsafe { &mut *delay_on },
+                // SAFETY: The function's contract guarantees that `delay_off` points to a `usize`
+                // and is exclusive for the period of this function.
+                unsafe { &mut *delay_off },
+            )?;
+            Ok(0)
+        })
+    }
+}
+
+#[pinned_drop]
+impl<T: LedOps> PinnedDrop for Device<T> {
+    fn drop(self: Pin<&mut Self>) {
+        let raw = self.classdev.get();
+        // SAFETY: The existence of `self` guarantees that `self.classdev.get()` is a pointer to a
+        // valid `struct led_classdev`.
+        let dev: &device::Device = unsafe { device::Device::from_raw((*raw).dev) };
+
+        let _fwnode = dev
+            .fwnode()
+            // SAFETY: the reference count of `fwnode` has previously been
+            // incremented in `led::Device::new`.
+            .map(|fwnode| unsafe { ARef::from_raw(NonNull::from(fwnode)) });
+
+        // SAFETY: The existence of `self` guarantees that `self.classdev` has previously been
+        // successfully registered with `led_classdev_register_ext`.
+        unsafe { bindings::led_classdev_unregister(self.classdev.get()) };
+    }
+}
rust/kernel/lib.rs +1 -0
index e5247f584ad2..f42c60da21ae 100644
@@ -97,6 +97,7 @@
 pub mod jump_label;
 #[cfg(CONFIG_KUNIT)]
 pub mod kunit;
+pub mod led;
 pub mod list;
 pub mod miscdevice;
 pub mod mm;
Signature · 1 line
2.49.1
#3 lore raw

Re: [PATCH v3 2/2] rust: leds: add basic led classdev abstractions

kernel test robot noticed the following build errors:

Hi Markus,

kernel test robot noticed the following build errors:

[auto build test ERROR on lee-leds/for-leds-next]
[also build test ERROR on v6.17]
[cannot apply to rust/rust-next rust/alloc-next linus/master next-20251010] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Markus-Probst/rust-add-basic-Pin-Vec-T-A-abstractions/20251011-065458
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/leds.git for-leds-next
patch link:    https://lore.kernel.org/r/20251010225349.734350-3-markus.probst%40posteo.de
patch subject: [PATCH v3 2/2] rust: leds: add basic led classdev abstractions
config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20251012/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251012/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> error[E0277]: the trait bound `rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>: LedOps` is not satisfied
   --> rust/doctests_kernel_generated.rs:6097:6
   |
   6097 | /      KBox::pin_init(led::Device::new(
   6098 | |          None,
   6099 | |          None,
   6100 | |          led::InitData::new()
   6101 | |              .default_label(c_str!("my_led")),
   6102 | |          MyLedOps,
   6103 | |      ))
   | |_______^ the trait `LedOps` is not implemented for `rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>`
   |

= help: the trait LedOps is implemented for MyLedOps
note: required by a bound in rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::Device --> rust/kernel/led.rs:26:22
|
26 | pub struct Device<T: LedOps> {
| ^^^^^^ required by this bound in Device
--

>> error[E0277]: `UnsafeCell<MaybeUninit<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>>` cannot be shared between threads safely
   --> rust/doctests_kernel_generated.rs:6097:6
   |
   6097 | /      KBox::pin_init(led::Device::new(
   6098 | |          None,
   6099 | |          None,
   6100 | |          led::InitData::new()
   6101 | |              .default_label(c_str!("my_led")),
   6102 | |          MyLedOps,
   6103 | |      ))
   | |_______^ `UnsafeCell<MaybeUninit<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>>` cannot be shared between threads safely
   |

= help: within FwNode, the trait Sync is not implemented for UnsafeCell<MaybeUninit<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>>
note: required because it appears within the type Opaque<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>
--> rust/kernel/types.rs:324:12
|
324 | pub struct Opaque<T> {
| ^^^^^^
note: required because it appears within the type FwNode
--> rust/kernel/device/property.rs:35:12
|
35 | pub struct FwNode(Opaque<bindings::fwnode_handle>);
| ^^^^^^
= note: required for &FwNode to implement Send
note: required because it appears within the type Option<&FwNode>
--> /opt/cross/rustc-1.88.0-bindgen-0.72.0/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:589:10 |
589 | pub enum Option<T> {
| ^^^^^^
note: required because it appears within the type rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>
--> rust/kernel/led.rs:36:12
|
36 | pub struct InitData<'a> {
| ^^^^^^^^
= note: required for Device<InitData<'_>> to implement Send
note: required by a bound in Devres
--> rust/kernel/devres.rs:108:22
|
108 | pub struct Devres<T: Send> {
| ^^^^ required by this bound in Devres
= note: the full name for the type has been written to 'rust/doctests_kernel_generated.long-type-938713932875159562.txt'
= note: consider using --verbose to print the full type name to the console
--

>> error[E0107]: missing generics for struct `rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::Device`

--> rust/doctests_kernel_generated.rs:6096:47
|
6096 | fn register_my_led() -> Result<Pin<KBox<led::Device>>> {
| ^^^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: T --> rust/kernel/led.rs:26:12
|
26 | pub struct Device<T: LedOps> {
| ^^^^^^ -
help: add missing generic argument
|
6096 | fn register_my_led() -> Result<Pin<KBox<led::Device<T>>>> {
| +++
--

>> error[E0277]: the trait bound `rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>: LedOps` is not satisfied
   --> rust/doctests_kernel_generated.rs:6100:10
   |
   6097 |        KBox::pin_init(led::Device::new(
   |                       ---------------- required by a bound introduced by this call
   ...
   6100 | /          led::InitData::new()
   6101 | |              .default_label(c_str!("my_led")),
   | |_____________________________________________^ the trait `LedOps` is not implemented for `rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>`
   |

= help: the trait LedOps is implemented for MyLedOps
note: required by a bound in rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::Device::<T>::new --> rust/kernel/led.rs:168:9
|
168 | impl<T: LedOps> Device<T> {
| ^^^^^^ required by this bound in Device::<T>::new
...
172 | pub fn new<'a>(
| --- required by a bound in this associated function
--

>> error[E0277]: the trait bound `rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>: LedOps` is not satisfied
   --> rust/doctests_kernel_generated.rs:6097:21
   |
   6097 |        KBox::pin_init(led::Device::new(
   |  _____________________^
   6098 | |          None,
   6099 | |          None,
   6100 | |          led::InitData::new()
   6101 | |              .default_label(c_str!("my_led")),
   6102 | |          MyLedOps,
   6103 | |      ))
   | |______^ the trait `LedOps` is not implemented for `rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>`
   |

= help: the trait LedOps is implemented for MyLedOps
note: required by a bound in rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::Device<T> --> rust/kernel/led.rs:168:9
|
168 | impl<T: LedOps> Device<T> {
| ^^^^^^ required by this bound in Device<T>
--

>> error[E0277]: the trait bound `rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>: LedOps` is not satisfied

--> rust/doctests_kernel_generated.rs:6097:6
|
6097 | KBox::pin_init(led::Device::new(
| ^^^^^^^^^^^^^^ the trait LedOps is not implemented for rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>
|
= help: the trait LedOps is implemented for MyLedOps
note: required by a bound in rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::Device --> rust/kernel/led.rs:26:22
|
26 | pub struct Device<T: LedOps> {
| ^^^^^^ required by this bound in Device
--

>> error[E0277]: `UnsafeCell<MaybeUninit<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>>` cannot be shared between threads safely

--> rust/doctests_kernel_generated.rs:6097:6
|
6097 | KBox::pin_init(led::Device::new(
| ^^^^^^^^^^^^^^ UnsafeCell<MaybeUninit<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>> cannot be shared between threads safely
|
= help: within FwNode, the trait Sync is not implemented for UnsafeCell<MaybeUninit<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>>
note: required because it appears within the type Opaque<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>
--> rust/kernel/types.rs:324:12
|
324 | pub struct Opaque<T> {
| ^^^^^^
note: required because it appears within the type FwNode
--> rust/kernel/device/property.rs:35:12
|
35 | pub struct FwNode(Opaque<bindings::fwnode_handle>);
| ^^^^^^
= note: required for &FwNode to implement Send
note: required because it appears within the type Option<&FwNode>
--> /opt/cross/rustc-1.88.0-bindgen-0.72.0/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:589:10 |
589 | pub enum Option<T> {
| ^^^^^^
note: required because it appears within the type rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>
--> rust/kernel/led.rs:36:12
|
36 | pub struct InitData<'a> {
| ^^^^^^^^
= note: required for Device<InitData<'_>> to implement Send
note: required by a bound in Devres
--> rust/kernel/devres.rs:108:22
|
108 | pub struct Devres<T: Send> {
| ^^^^ required by this bound in Devres
= note: the full name for the type has been written to 'rust/doctests_kernel_generated.long-type-938713932875159562.txt'
= note: consider using --verbose to print the full type name to the console
--

>> error[E0277]: the trait bound `rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>: LedOps` is not satisfied

--> rust/doctests_kernel_generated.rs:6097:6
|
6097 | KBox::pin_init(led::Device::new(
| ^^^^ the trait LedOps is not implemented for rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>
|
= help: the trait LedOps is implemented for MyLedOps
note: required by a bound in rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::Device --> rust/kernel/led.rs:26:22
|
26 | pub struct Device<T: LedOps> {
| ^^^^^^ required by this bound in Device
--

>> error[E0277]: `UnsafeCell<MaybeUninit<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>>` cannot be shared between threads safely

--> rust/doctests_kernel_generated.rs:6097:6
|
6097 | KBox::pin_init(led::Device::new(
| ^^^^ UnsafeCell<MaybeUninit<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>> cannot be shared between threads safely
|
= help: within FwNode, the trait Sync is not implemented for UnsafeCell<MaybeUninit<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>>
note: required because it appears within the type Opaque<rust_doctest_kernel_alloc_kbox_rs_7::kernel::bindings::fwnode_handle>
--> rust/kernel/types.rs:324:12
|
324 | pub struct Opaque<T> {
| ^^^^^^
note: required because it appears within the type FwNode
--> rust/kernel/device/property.rs:35:12
|
35 | pub struct FwNode(Opaque<bindings::fwnode_handle>);
| ^^^^^^
= note: required for &FwNode to implement Send
note: required because it appears within the type Option<&FwNode>
--> /opt/cross/rustc-1.88.0-bindgen-0.72.0/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:589:10 |
589 | pub enum Option<T> {
| ^^^^^^
note: required because it appears within the type rust_doctest_kernel_alloc_kbox_rs_7::kernel::led::InitData<'_>
--> rust/kernel/led.rs:36:12
|
36 | pub struct InitData<'a> {
| ^^^^^^^^
= note: required for Device<InitData<'_>> to implement Send
note: required by a bound in Devres
--> rust/kernel/devres.rs:108:22
|
108 | pub struct Devres<T: Send> {
| ^^^^ required by this bound in Devres
= note: the full name for the type has been written to 'rust/doctests_kernel_generated.long-type-938713932875159562.txt'
= note: consider using --verbose to print the full type name to the console

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki