Skip to content

Commit dfafc6f

Browse files
committed
rust: io_mem: Add helper to construct a Resource from bindings:resource
This will be used in multiple code paths later. Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent fd02dfd commit dfafc6f

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

rust/kernel/io_mem.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ impl Resource {
3737
flags,
3838
})
3939
}
40+
41+
pub(crate) fn new_from_resource(res: &bindings::resource) -> Option<Self> {
42+
Self::new(res.start, res.end, res.flags)
43+
}
4044
}
4145

4246
/// Represents a memory block of at least `SIZE` bytes.

rust/kernel/platform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl Device {
251251

252252
// SAFETY: The pointer `res` is returned from `bindings::platform_get_resource`
253253
// above and checked if it is not a NULL.
254-
unsafe { Resource::new((*res).start, (*res).end, (*res).flags) }.ok_or(EINVAL)
254+
Resource::new_from_resource(unsafe { &*res }).ok_or(EINVAL)
255255
}
256256

257257
/// Ioremaps resources of a platform device.

0 commit comments

Comments
 (0)