@@ -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).
451459pub 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).
456472pub 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).
461485pub 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).
466498pub 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