Skip to content

Commit 6ac08f2

Browse files
committed
rust: io: resource: Add owned Resource initialiser
Some C functions like of_reserved_mem_region_to_resource_byname() expect a pointer to a `struct resource` so provide ::zeroed() as initialiser and ::as_raw() so other parts in the kernel crate can use functions which expect such a pointer. Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 0a1d754 commit 6ac08f2

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

rust/kernel/io/resource.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ unsafe impl Sync for Region {}
8989
pub struct Resource(Opaque<bindings::resource>);
9090

9191
impl Resource {
92+
/// Create a new zeroed [`Resource`]
93+
pub(crate) fn zeroed() -> Self {
94+
Resource {
95+
0: Opaque::<bindings::resource>::zeroed(),
96+
}
97+
}
98+
99+
/// Gets the raw pointer to the wrapped `bindings::resource`.
100+
pub(crate) fn as_raw(&self) -> *mut bindings::resource {
101+
self.0.get()
102+
}
103+
92104
/// Creates a reference to a [`Resource`] from a valid pointer.
93105
///
94106
/// # Safety

0 commit comments

Comments
 (0)