@@ -390,6 +390,13 @@ impl<'a> Fdt<'a> {
390390 /// first. [`DeviceTree`](crate::model::DeviceTree) stores the nodes in a
391391 /// hash map for constant-time lookup.
392392 ///
393+ /// # Errors
394+ ///
395+ /// Returns an [`FdtErrorKind::InvalidLength`] if the FDT structure is
396+ /// truncated or, an [`FdtErrorKind::BadToken`] if an unexpected token is
397+ /// encountered while searching, or an [`FdtErrorKind::InvalidString`] if a
398+ /// node has an invalid name.
399+ ///
393400 /// # Examples
394401 ///
395402 /// ```
@@ -409,17 +416,13 @@ impl<'a> Fdt<'a> {
409416 /// let node = fdt.find_node("/child2@42").unwrap().unwrap();
410417 /// assert_eq!(node.name().unwrap(), "child2@42");
411418 /// ```
412- #[ must_use]
413- pub fn find_node ( & self , path : & str ) -> Option < Result < FdtNode < ' _ > , FdtError > > {
419+ pub fn find_node ( & self , path : & str ) -> Result < Option < FdtNode < ' _ > > , FdtError > {
414420 if !path. starts_with ( '/' ) {
415- return None ;
421+ return Ok ( None ) ;
416422 }
417- let mut current_node = match self . root ( ) {
418- Ok ( node) => node,
419- Err ( e) => return Some ( Err ( e) ) ,
420- } ;
423+ let mut current_node = self . root ( ) ?;
421424 if path == "/" {
422- return Some ( Ok ( current_node) ) ;
425+ return Ok ( Some ( current_node) ) ;
423426 }
424427 for component in path. split ( '/' ) . filter ( |s| !s. is_empty ( ) ) {
425428 let include_address = component. contains ( '@' ) ;
@@ -433,11 +436,11 @@ impl<'a> Fdt<'a> {
433436 } )
434437 } ) {
435438 Some ( Ok ( node) ) => current_node = node,
436- Some ( Err ( e) ) => return Some ( Err ( e) ) ,
437- None => return None ,
439+ Some ( Err ( e) ) => return Err ( e) ,
440+ None => return Ok ( None ) ,
438441 }
439442 }
440- Some ( Ok ( current_node) )
443+ Ok ( Some ( current_node) )
441444 }
442445
443446 pub ( crate ) fn read_token ( & self , offset : usize ) -> Result < FdtToken , FdtError > {
0 commit comments