Skip to content

Commit 2d71bbc

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

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
@@ -119,7 +119,15 @@ impl Node {
119119

120120
/// Returns `true` if the node is the root node.
121121
pub fn is_root(&self) -> bool {
122-
unsafe { bindings::of_node_is_root(self.raw_node) }
122+
#[cfg(not(CONFIG_OF))]
123+
{
124+
false
125+
}
126+
#[cfg(CONFIG_OF)]
127+
// SAFETY: `raw_node` is valid per the type invariant
128+
unsafe {
129+
bindings::of_node_is_root(self.raw_node)
130+
}
123131
}
124132

125133
/// Returns the parent node, if any.
@@ -452,22 +460,54 @@ where
452460

453461
/// Returns the root node of the OF device tree (if any).
454462
pub fn root() -> Option<Node> {
455-
unsafe { Node::get_from_raw(bindings::of_root) }
463+
#[cfg(not(CONFIG_OF))]
464+
{
465+
None
466+
}
467+
#[cfg(CONFIG_OF)]
468+
// SAFETY: bindings::of_root is always valid or NULL
469+
unsafe {
470+
Node::get_from_raw(bindings::of_root)
471+
}
456472
}
457473

458474
/// Returns the /chosen node of the OF device tree (if any).
459475
pub fn chosen() -> Option<Node> {
460-
unsafe { Node::get_from_raw(bindings::of_chosen) }
476+
#[cfg(not(CONFIG_OF))]
477+
{
478+
None
479+
}
480+
#[cfg(CONFIG_OF)]
481+
// SAFETY: bindings::of_chosen is always valid or NULL
482+
unsafe {
483+
Node::get_from_raw(bindings::of_chosen)
484+
}
461485
}
462486

463487
/// Returns the /aliases node of the OF device tree (if any).
464488
pub fn aliases() -> Option<Node> {
465-
unsafe { Node::get_from_raw(bindings::of_aliases) }
489+
#[cfg(not(CONFIG_OF))]
490+
{
491+
None
492+
}
493+
#[cfg(CONFIG_OF)]
494+
// SAFETY: bindings::of_aliases is always valid or NULL
495+
unsafe {
496+
Node::get_from_raw(bindings::of_aliases)
497+
}
466498
}
467499

468500
/// Returns the system stdout node of the OF device tree (if any).
469501
pub fn stdout() -> Option<Node> {
470-
unsafe { Node::get_from_raw(bindings::of_stdout) }
502+
#[cfg(not(CONFIG_OF))]
503+
{
504+
None
505+
}
506+
#[cfg(CONFIG_OF)]
507+
// SAFETY: bindings::of_stdout is always valid or NULL
508+
unsafe {
509+
Node::get_from_raw(bindings::of_stdout)
510+
}
471511
}
472512

473513
#[allow(unused_variables)]

0 commit comments

Comments
 (0)