Skip to content

Commit cd826a0

Browse files
marcanjannau
authored andcommitted
rust: Fix x86 build
Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent dcb4bbd commit cd826a0

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

rust/helpers/of.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ const struct of_device_id *rust_helper_of_match_device(
88
{
99
return of_match_device(matches, dev);
1010
}
11+
12+
#ifdef CONFIG_OF
1113
bool rust_helper_of_node_is_root(const struct device_node *np)
1214
{
1315
return of_node_is_root(np);
1416
}
17+
#endif
1518

1619
struct device_node *rust_helper_of_parse_phandle(const struct device_node *np,
1720
const char *phandle_name,

rust/kernel/of.rs

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ impl Node {
116116

117117
/// Returns `true` if the node is the root node.
118118
pub fn is_root(&self) -> bool {
119-
unsafe { bindings::of_node_is_root(self.raw_node) }
119+
#[cfg(not(CONFIG_OF))]
120+
{
121+
false
122+
}
123+
#[cfg(CONFIG_OF)]
124+
// SAFETY: `raw_node` is valid per the type invariant
125+
unsafe {
126+
bindings::of_node_is_root(self.raw_node)
127+
}
120128
}
121129

122130
/// Returns the parent node, if any.
@@ -449,22 +457,54 @@ where
449457

450458
/// Returns the root node of the OF device tree (if any).
451459
pub fn root() -> Option<Node> {
452-
unsafe { Node::get_from_raw(bindings::of_root) }
460+
#[cfg(not(CONFIG_OF))]
461+
{
462+
None
463+
}
464+
#[cfg(CONFIG_OF)]
465+
// SAFETY: bindings::of_root is always valid or NULL
466+
unsafe {
467+
Node::get_from_raw(bindings::of_root)
468+
}
453469
}
454470

455471
/// Returns the /chosen node of the OF device tree (if any).
456472
pub fn chosen() -> Option<Node> {
457-
unsafe { Node::get_from_raw(bindings::of_chosen) }
473+
#[cfg(not(CONFIG_OF))]
474+
{
475+
None
476+
}
477+
#[cfg(CONFIG_OF)]
478+
// SAFETY: bindings::of_chosen is always valid or NULL
479+
unsafe {
480+
Node::get_from_raw(bindings::of_chosen)
481+
}
458482
}
459483

460484
/// Returns the /aliases node of the OF device tree (if any).
461485
pub fn aliases() -> Option<Node> {
462-
unsafe { Node::get_from_raw(bindings::of_aliases) }
486+
#[cfg(not(CONFIG_OF))]
487+
{
488+
None
489+
}
490+
#[cfg(CONFIG_OF)]
491+
// SAFETY: bindings::of_aliases is always valid or NULL
492+
unsafe {
493+
Node::get_from_raw(bindings::of_aliases)
494+
}
463495
}
464496

465497
/// Returns the system stdout node of the OF device tree (if any).
466498
pub fn stdout() -> Option<Node> {
467-
unsafe { Node::get_from_raw(bindings::of_stdout) }
499+
#[cfg(not(CONFIG_OF))]
500+
{
501+
None
502+
}
503+
#[cfg(CONFIG_OF)]
504+
// SAFETY: bindings::of_stdout is always valid or NULL
505+
unsafe {
506+
Node::get_from_raw(bindings::of_stdout)
507+
}
468508
}
469509

470510
#[allow(unused_variables)]

0 commit comments

Comments
 (0)