@@ -18,7 +18,7 @@ use std::mem;
1818
1919use vm_memory:: { Address , ByteValued , Bytes , GuestAddress , GuestMemory , GuestUsize } ;
2020
21- use super :: { Error as KernelLoaderError , KernelLoader , KernelLoaderResult , Result } ;
21+ use super :: super :: { Error as KernelLoaderError , KernelLoader , KernelLoaderResult , Result } ;
2222
2323#[ allow( dead_code) ]
2424#[ allow( non_camel_case_types) ]
@@ -151,12 +151,12 @@ impl KernelLoader for Elf {
151151 /// let gm = GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), mem_size)]).unwrap();
152152 /// let mut kernel_image = vec![];
153153 /// kernel_image.extend_from_slice(include_bytes!("test_elf.bin"));
154- /// assert!( Elf::load(
154+ /// elf:: Elf::load(
155155 /// &gm,
156156 /// Some(kernel_addr),
157157 /// &mut Cursor::new(&kernel_image),
158158 /// Some(himem_start),
159- /// ).is_ok() );
159+ /// ).unwrap( );
160160 /// ```
161161 ///
162162 /// [`GuestMemory`]: https://docs.rs/vm-memory/latest/vm_memory/guest_memory/trait.GuestMemory.html
@@ -182,7 +182,7 @@ impl KernelLoader for Elf {
182182 Self :: validate_header ( & ehdr) ?;
183183 if let Some ( addr) = highmem_start_address {
184184 if ( ehdr. e_entry as u64 ) < addr. raw_value ( ) {
185- Err ( Error :: InvalidEntryAddress ) ? ;
185+ return Err ( Error :: InvalidEntryAddress . into ( ) ) ;
186186 }
187187 }
188188
@@ -252,19 +252,19 @@ fn parse_elf_note<F>(phdr: &elf::Elf64_Phdr, kernel_image: &mut F) -> Result<Opt
252252where
253253 F : Read + Seek ,
254254{
255- // Type of note header that encodes a 32-bit entry point address
256- // to boot a guest kernel using the PVH boot protocol.
255+ // Type of note header that encodes a 32-bit entry point address to boot a guest kernel using
256+ // the PVH boot protocol.
257257 const XEN_ELFNOTE_PHYS32_ENTRY : u32 = 18 ;
258258
259259 let n_align = phdr. p_align ;
260260
261- // Seek to the beginning of the note segment
261+ // Seek to the beginning of the note segment.
262262 kernel_image
263263 . seek ( SeekFrom :: Start ( phdr. p_offset ) )
264264 . map_err ( |_| Error :: SeekNoteHeader ) ?;
265265
266- // Now that the segment has been found, we must locate an ELF note with the
267- // correct type that encodes the PVH entry point if there is one.
266+ // Now that the segment has been found, we must locate an ELF note with the correct type that
267+ // encodes the PVH entry point if there is one.
268268 let mut nhdr: elf:: Elf64_Nhdr = Default :: default ( ) ;
269269 let mut read_size: usize = 0 ;
270270 let nhdr_sz = mem:: size_of :: < elf:: Elf64_Nhdr > ( ) ;
@@ -274,12 +274,12 @@ where
274274 . read_from ( 0 , kernel_image, nhdr_sz)
275275 . map_err ( |_| Error :: ReadNoteHeader ) ?;
276276
277- // If the note header found is not the desired one, keep reading until
278- // the end of the segment
277+ // If the note header found is not the desired one, keep reading until the end of the
278+ // segment.
279279 if nhdr. n_type == XEN_ELFNOTE_PHYS32_ENTRY {
280280 break ;
281281 }
282- // Skip the note header plus the size of its fields (with alignment)
282+ // Skip the note header plus the size of its fields (with alignment).
283283 read_size += nhdr_sz
284284 + align_up ( u64:: from ( nhdr. n_namesz ) , n_align)
285285 + align_up ( u64:: from ( nhdr. n_descsz ) , n_align) ;
@@ -290,21 +290,23 @@ where
290290 }
291291
292292 if read_size >= phdr. p_filesz as usize {
293- return Ok ( None ) ; // PVH ELF note not found, nothing else to do.
293+ // PVH ELF note not found, nothing else to do.
294+ return Ok ( None ) ;
294295 }
296+
295297 // Otherwise the correct note type was found.
296- // The note header struct has already been read, so we can seek from the
297- // current position and just skip the name field contents.
298+ // The note header struct has already been read, so we can seek from the current position and
299+ // just skip the name field contents.
298300 kernel_image
299301 . seek ( SeekFrom :: Current (
300302 align_up ( u64:: from ( nhdr. n_namesz ) , n_align) as i64 ,
301303 ) )
302304 . map_err ( |_| Error :: SeekNoteHeader ) ?;
303305
304- // The PVH entry point is a 32-bit address, so the descriptor field
305- // must be capable of storing all such addresses.
306+ // The PVH entry point is a 32-bit address, so the descriptor field must be capable of storing
307+ // all such addresses.
306308 if ( nhdr. n_descsz as usize ) < mem:: size_of :: < u32 > ( ) {
307- Err ( Error :: InvalidPvhNote ) ? ;
309+ return Err ( Error :: InvalidPvhNote . into ( ) ) ;
308310 }
309311
310312 let mut pvh_addr_bytes = [ 0 ; mem:: size_of :: < u32 > ( ) ] ;
0 commit comments