Skip to content

Commit 8afbb3b

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 dbbb076 commit 8afbb3b

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

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

0 commit comments

Comments
 (0)