summaryrefslogtreecommitdiff
path: root/rust/kernel/of.rs
diff options
context:
space:
mode:
authorThomas Zimmermann <tzimmermann@suse.de>2025-08-11 14:37:45 +0200
committerThomas Zimmermann <tzimmermann@suse.de>2025-08-11 14:37:45 +0200
commit08c51f5bddc81c8c97c1eb11861b0dc009e5ccd8 (patch)
treee40424bafb75c8661afbdb55cfd52d7e0c133023 /rust/kernel/of.rs
parent1bf30a45653d14b0d88b5ca3c72e0ecf030d9c88 (diff)
parent8f5ae30d69d7543eee0d70083daf4de8fe15d585 (diff)
Merge drm/drm-next into drm-misc-n
Updating drm-misc-next to the state of v6.17-rc1. Begins a new release cycle. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Diffstat (limited to 'rust/kernel/of.rs')
-rw-r--r--rust/kernel/of.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/rust/kernel/of.rs b/rust/kernel/of.rs
index 04f2d8ef29cb..b76b35265df2 100644
--- a/rust/kernel/of.rs
+++ b/rust/kernel/of.rs
@@ -2,7 +2,11 @@
//! Device Tree / Open Firmware abstractions.
-use crate::{bindings, device_id::RawDeviceId, prelude::*};
+use crate::{
+ bindings,
+ device_id::{RawDeviceId, RawDeviceIdIndex},
+ prelude::*,
+};
/// IdTable type for OF drivers.
pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<DeviceId, T>;
@@ -12,17 +16,18 @@ pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<DeviceId, T>;
#[derive(Clone, Copy)]
pub struct DeviceId(bindings::of_device_id);
-// SAFETY:
-// * `DeviceId` is a `#[repr(transparent)` wrapper of `struct of_device_id` and does not add
-// additional invariants, so it's safe to transmute to `RawType`.
-// * `DRIVER_DATA_OFFSET` is the offset to the `data` field.
+// SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `struct of_device_id` and
+// does not add additional invariants, so it's safe to transmute to `RawType`.
unsafe impl RawDeviceId for DeviceId {
type RawType = bindings::of_device_id;
+}
+// SAFETY: `DRIVER_DATA_OFFSET` is the offset to the `data` field.
+unsafe impl RawDeviceIdIndex for DeviceId {
const DRIVER_DATA_OFFSET: usize = core::mem::offset_of!(bindings::of_device_id, data);
fn index(&self) -> usize {
- self.0.data as _
+ self.0.data as usize
}
}
@@ -34,10 +39,10 @@ impl DeviceId {
// SAFETY: FFI type is valid to be zero-initialized.
let mut of: bindings::of_device_id = unsafe { core::mem::zeroed() };
- // TODO: Use `clone_from_slice` once the corresponding types do match.
+ // TODO: Use `copy_from_slice` once stabilized for `const`.
let mut i = 0;
while i < src.len() {
- of.compatible[i] = src[i] as _;
+ of.compatible[i] = src[i];
i += 1;
}