Skip to content

Commit 5b713a2

Browse files
committed
fixup! rust: of: Add OF node abstraction
1 parent 69f6ac7 commit 5b713a2

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

rust/helpers/helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "kunit.c"
1919
#include "lockdep.c"
2020
#include "mutex.c"
21+
#include "of.c"
2122
#include "page.c"
2223
#include "platform.c"
2324
#include "pci.c"

rust/kernel/device.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! C header: [`include/linux/device.h`](srctree/include/linux/device.h)
66
77
use crate::{
8-
bindings,
8+
bindings, of,
99
types::{ARef, Opaque},
1010
};
1111
use core::{fmt, ptr};
@@ -77,6 +77,13 @@ impl Device {
7777
unsafe { &*ptr.cast() }
7878
}
7979

80+
/// Gets the OpenFirmware node attached to this device
81+
pub fn of_node(&self) -> Option<of::Node> {
82+
let ptr = self.0.get();
83+
// SAFETY: This is safe as long as of_node is NULL or valid.
84+
unsafe { of::Node::get_from_raw((*ptr).of_node) }
85+
}
86+
8087
/// Prints an emergency-level message (level 0) prefixed with device information.
8188
///
8289
/// More details are available from [`dev_emerg`].

rust/kernel/of.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@ use crate::{bindings, device_id::RawDeviceId, prelude::*};
1010
// here for now. In the future, once bindgen can auto-generate static inline
1111
// helpers, this can go away if desired.
1212

13-
//use core::marker::PhantomData;
14-
//use core::num::NonZeroU32;
15-
16-
//use crate::{
17-
// alloc::flags::*,
18-
// bindings, driver,
19-
// prelude::*,
20-
// str::{BStr, CStr},
21-
//};
13+
use core::marker::PhantomData;
14+
use core::num::NonZeroU32;
2215

2316
/// An open firmware device id.
2417
#[derive(Clone, Copy)]
@@ -339,10 +332,10 @@ pub trait PropertyUnit: Sized {
339332
// }
340333
// }
341334

342-
impl<'a, T: PropertyUnit> TryFrom<Property<'a>> for Vec<T> {
335+
impl<'a, T: PropertyUnit> TryFrom<Property<'a>> for KVec<T> {
343336
type Error = Error;
344337

345-
fn try_from(p: Property<'_>) -> core::result::Result<Vec<T>, Self::Error> {
338+
fn try_from(p: Property<'_>) -> core::result::Result<KVec<T>, Self::Error> {
346339
if p.len() % T::UNIT_SIZE != 0 {
347340
return Err(EINVAL);
348341
}

0 commit comments

Comments
 (0)