Skip to content

Commit 0c779db

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 339e976 commit 0c779db

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
@@ -79,6 +79,18 @@ unsafe impl Sync for Region {}
7979
pub struct Resource(Opaque<bindings::resource>);
8080

8181
impl Resource {
82+
/// Create a new zeroed [`Resource`]
83+
pub(crate) fn zeroed() -> Self {
84+
Resource {
85+
0: Opaque::<bindings::resource>::zeroed(),
86+
}
87+
}
88+
89+
/// Gets the raw pointer to the wrapped `bindings::resource`.
90+
pub(crate) fn as_raw(&self) -> *mut bindings::resource {
91+
self.0.get()
92+
}
93+
8294
/// Creates a reference to a [`Resource`] from a valid pointer.
8395
///
8496
/// # Safety

0 commit comments

Comments
 (0)