@@ -167,7 +167,9 @@ impl Node {
167167 false
168168 }
169169 #[ cfg( CONFIG_OF ) ]
170- unsafe { bindings:: of_node_is_root ( self . raw_node ) }
170+ unsafe {
171+ bindings:: of_node_is_root ( self . raw_node )
172+ }
171173 }
172174
173175 /// Returns the parent node, if any.
@@ -500,22 +502,54 @@ where
500502
501503/// Returns the root node of the OF device tree (if any).
502504pub fn root ( ) -> Option < Node > {
503- unsafe { Node :: get_from_raw ( bindings:: of_root) }
505+ #[ cfg( not( CONFIG_OF ) ) ]
506+ {
507+ None
508+ }
509+ #[ cfg( CONFIG_OF ) ]
510+ // SAFETY: bindings::of_root is always valid or NULL
511+ unsafe {
512+ Node :: get_from_raw ( bindings:: of_root)
513+ }
504514}
505515
506516/// Returns the /chosen node of the OF device tree (if any).
507517pub fn chosen ( ) -> Option < Node > {
508- unsafe { Node :: get_from_raw ( bindings:: of_chosen) }
518+ #[ cfg( not( CONFIG_OF ) ) ]
519+ {
520+ None
521+ }
522+ #[ cfg( CONFIG_OF ) ]
523+ // SAFETY: bindings::of_chosen is always valid or NULL
524+ unsafe {
525+ Node :: get_from_raw ( bindings:: of_chosen)
526+ }
509527}
510528
511529/// Returns the /aliases node of the OF device tree (if any).
512530pub fn aliases ( ) -> Option < Node > {
513- unsafe { Node :: get_from_raw ( bindings:: of_aliases) }
531+ #[ cfg( not( CONFIG_OF ) ) ]
532+ {
533+ None
534+ }
535+ #[ cfg( CONFIG_OF ) ]
536+ // SAFETY: bindings::of_aliases is always valid or NULL
537+ unsafe {
538+ Node :: get_from_raw ( bindings:: of_aliases)
539+ }
514540}
515541
516542/// Returns the system stdout node of the OF device tree (if any).
517543pub fn stdout ( ) -> Option < Node > {
518- unsafe { Node :: get_from_raw ( bindings:: of_stdout) }
544+ #[ cfg( not( CONFIG_OF ) ) ]
545+ {
546+ None
547+ }
548+ #[ cfg( CONFIG_OF ) ]
549+ // SAFETY: bindings::of_stdout is always valid or NULL
550+ unsafe {
551+ Node :: get_from_raw ( bindings:: of_stdout)
552+ }
519553}
520554
521555#[ allow( unused_variables) ]
0 commit comments