@@ -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).
454462pub 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).
459475pub 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).
464488pub 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).
469501pub 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