Browse Source

rustsbi: code quality fix using clippy hints

Signed-off-by: luojia65 <[email protected]>
luojia65 3 years ago
parent
commit
2c9cbf18da
7 changed files with 10 additions and 15 deletions
  1. 2 4
      src/hart_mask.rs
  2. 1 1
      src/hsm.rs
  3. 2 5
      src/ipi.rs
  4. 1 1
      src/lib.rs
  5. 1 1
      src/logo.rs
  6. 1 1
      src/privileged.rs
  7. 2 2
      src/util.rs

+ 2 - 4
src/hart_mask.rs

@@ -1,5 +1,3 @@
-use core::mem::size_of;
-
 /// Hart mask structure reference
 #[derive(Debug, Clone)]
 pub struct HartMask {
@@ -19,7 +17,7 @@ impl HartMask {
     ///   If `base` equals `usize::MAX`, that means `vaddr` is ignored and all available harts must be considered.
     /// - The `max_hart_id` should be returned by SBI implementation for maximum hart id this hart mask supports.
     ///
-    /// # Unsafety
+    /// # Safety
     ///
     /// Caller must ensure all usize values in the bit vector is accessible.
     pub unsafe fn from_addr(vaddr: usize, base: usize, max_hart_id: usize) -> HartMask {
@@ -49,7 +47,7 @@ impl HartMask {
 
 #[inline]
 fn split_index_usize(index: usize) -> (usize, usize) {
-    let bits_in_usize = size_of::<usize>() * 8;
+    let bits_in_usize = usize::BITS as usize;
     (index / bits_in_usize, index % bits_in_usize)
 }
 

+ 1 - 1
src/hsm.rs

@@ -185,7 +185,7 @@ pub trait Hsm: Send {
     /// | SBI_ERR_INVALID_ADDRESS | `resume_addr` is not valid possibly due to following reasons: it is not a valid physical address, or the address is prohibited by PMP to run in supervisor mode.
     /// | SBI_ERR_FAILED          | The suspend request failed for unknown reasons.
     fn hart_suspend(&self, suspend_type: u32, resume_addr: usize, opaque: usize) -> SbiRet {
-        drop((suspend_type, resume_addr, opaque));
+        let _ = (suspend_type, resume_addr, opaque);
         SbiRet::not_supported()
     }
 }

+ 2 - 5
src/ipi.rs

@@ -40,10 +40,7 @@ pub(crate) fn send_ipi_many(hart_mask: HartMask) -> SbiRet {
     }
 }
 
+// Returns maximum hart id if IPI presents, or None if absent.
 pub(crate) fn max_hart_id() -> Option<usize> {
-    if let Some(ipi) = IPI.get() {
-        Some(ipi.max_hart_id())
-    } else {
-        None
-    }
+    IPI.get().map(|ipi| ipi.max_hart_id())
 }

+ 1 - 1
src/lib.rs

@@ -193,7 +193,7 @@ const RUSTSBI_VERSION_PATCH: usize =
 const RUSTSBI_VERSION: usize =
     (RUSTSBI_VERSION_MAJOR << 16) + (RUSTSBI_VERSION_MINOR << 8) + RUSTSBI_VERSION_PATCH;
 /// RustSBI version as a string.
-pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
+pub const VERSION: &str = env!("CARGO_PKG_VERSION");
 
 pub use ecall::handle_ecall as ecall;
 pub use ecall::SbiRet;

+ 1 - 1
src/logo.rs

@@ -8,4 +8,4 @@
 /// |  |\  \----.|  `--'  |.----)   |      |  |  .----)   |   |  |_)  ||  |
 /// | _| `._____| \______/ |_______/       |__|  |_______/    |______/ |__|
 /// ```
-pub const LOGO: &'static str = include_str!("logo.txt");
+pub const LOGO: &str = include_str!("logo.txt");

+ 1 - 1
src/privileged.rs

@@ -8,7 +8,7 @@
 /// After this function is called, the stack pointer register `sp` is swapped with `mscratch`,
 /// and a `mret` is called to return to `mepc` address with target privilege.
 ///
-/// # Unsafety
+/// # Safety
 ///
 /// This function implictly returns to the program address with the address from `mepc` register.
 /// Caller must ensure that the value in `mepc` is a valid program address.

+ 2 - 2
src/util.rs

@@ -95,7 +95,7 @@ impl<T: ?Sized> OnceFatBox<T> {
                 options(nostack)
             );
             // critical section begin
-            if *self.thin_ptr.get() == ptr::null_mut() {
+            if self.thin_ptr.get().is_null() {
                 *self.thin_ptr.get() = data_address;
                 *(self.meta.as_ptr() as *mut _) = ptr::metadata(fat_ptr);
                 ans = Ok(())
@@ -107,7 +107,7 @@ impl<T: ?Sized> OnceFatBox<T> {
             );
             ans
         };
-        if let Err(_) = exchange {
+        if exchange.is_err() {
             let value = unsafe { Box::from_raw(fat_ptr) };
             return Err(value);
         }