[opentitantool] Clean up lint

Run `cargo clippy`; heed its advice.

Signed-off-by: Chris Frantz <cfrantz@google.com>
diff --git a/sw/host/opentitanlib/src/spiflash/flash.rs b/sw/host/opentitanlib/src/spiflash/flash.rs
index 5c739ed..500880b 100644
--- a/sw/host/opentitanlib/src/spiflash/flash.rs
+++ b/sw/host/opentitanlib/src/spiflash/flash.rs
@@ -93,14 +93,13 @@
             address < self.size,
             Error::AddressOutOfBounds(address, self.size)
         );
-        let mut buf = Vec::new();
-        buf.push(opcode);
+        let mut buf = vec![opcode];
         if self.address_mode == AddressMode::Mode4b {
             buf.push((address >> 24) as u8);
         }
         buf.push((address >> 16) as u8);
         buf.push((address >> 8) as u8);
-        buf.push((address >> 0) as u8);
+        buf.push(address as u8);
         Ok(buf)
     }
 
@@ -155,7 +154,7 @@
             // extension. If parsing fails a second time, just return the error.
             let result = Sfdp::try_from(&buf[..]);
             if result.is_ok() || tries > 0 {
-                return result.into();
+                return result;
             }
             buf.resize(Sfdp::length_required(&buf)?, 0);
             tries += 1;
diff --git a/sw/host/opentitanlib/src/spiflash/sfdp.rs b/sw/host/opentitanlib/src/spiflash/sfdp.rs
index a8dfa39..dc3edfd 100644
--- a/sw/host/opentitanlib/src/spiflash/sfdp.rs
+++ b/sw/host/opentitanlib/src/spiflash/sfdp.rs
@@ -297,7 +297,7 @@
     type Error = Error;
     fn try_from(buf: &[u8]) -> Result<Self, Self::Error> {
         let p = InternalJedecParams::try_from(buf)?;
-        let density = if p.density()? & 0x8000_0000 == 0 {
+        let size_bytes = if p.density()? & 0x8000_0000 == 0 {
             (p.density()? + 1) / 8
         } else {
             1u32 << ((p.density()? & 0x7FFF_FFFF) - 8)
@@ -316,7 +316,7 @@
             support_fast_read_114: p.support_fast_read_114()?,
             support_fast_read_222: p.support_fast_read_222()?,
             support_fast_read_444: p.support_fast_read_444()?,
-            density: density,
+            density: size_bytes,
             sector: [
                 Sector {
                     size: 1u32 << p.sector_type1_size()?,
@@ -459,9 +459,9 @@
             JedecParams::try_from(buf.get(start..end).ok_or(Error::SliceRange(start, end))?)?;
 
         let mut params = Vec::new();
-        for i in 1..=(header.nph as usize) {
-            let start = phdr[i].offset as usize;
-            let end = start + phdr[i].dwords as usize * 4;
+        for ph in phdr.iter().take((header.nph as usize) + 1).skip(1) {
+            let start = ph.offset as usize;
+            let end = start + ph.dwords as usize * 4;
             params.push(UnknownParams::try_from(
                 buf.get(start..end).ok_or(Error::SliceRange(start, end))?,
             )?);
diff --git a/sw/host/opentitanlib/src/transport/ultradebug/mod.rs b/sw/host/opentitanlib/src/transport/ultradebug/mod.rs
index 69a831f..92afe4a 100644
--- a/sw/host/opentitanlib/src/transport/ultradebug/mod.rs
+++ b/sw/host/opentitanlib/src/transport/ultradebug/mod.rs
@@ -114,14 +114,14 @@
     }
 
     fn uart(&self) -> Result<Box<dyn Uart>> {
-        Ok(Box::new(uart::UltradebugUart::open(&self)?))
+        Ok(Box::new(uart::UltradebugUart::open(self)?))
     }
 
     fn gpio(&self) -> Result<Box<dyn Gpio>> {
-        Ok(Box::new(gpio::UltradebugGpio::open(&self)?))
+        Ok(Box::new(gpio::UltradebugGpio::open(self)?))
     }
 
     fn spi(&self) -> Result<Box<dyn Target>> {
-        Ok(Box::new(spi::UltradebugSpi::open(&self)?))
+        Ok(Box::new(spi::UltradebugSpi::open(self)?))
     }
 }
diff --git a/sw/host/opentitanlib/src/util/parse_int.rs b/sw/host/opentitanlib/src/util/parse_int.rs
index beae994..6c2c8cf 100644
--- a/sw/host/opentitanlib/src/util/parse_int.rs
+++ b/sw/host/opentitanlib/src/util/parse_int.rs
@@ -14,9 +14,9 @@
     fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
 
     fn from_str(src: &str) -> Result<Self, ParseIntError> {
-        let (val, negative) = if let Some(v) = src.strip_prefix("-") {
+        let (val, negative) = if let Some(v) = src.strip_prefix('-') {
             (v, true)
-        } else if let Some(v) = src.strip_prefix("+") {
+        } else if let Some(v) = src.strip_prefix('+') {
             (v, false)
         } else {
             (src, false)
@@ -26,7 +26,7 @@
             Some("0x") | Some("0X") => (16, &val[2..]),
             Some("0o") | Some("0O") => (8, &val[2..]),
             Some("0b") | Some("0B") => (2, &val[2..]),
-            _ if val.starts_with("0") => (8, val),
+            _ if val.starts_with('0') => (8, val),
             _ => (10, val),
         };
 
diff --git a/sw/host/opentitantool/src/backend/mod.rs b/sw/host/opentitantool/src/backend/mod.rs
index 596957f..ac7fc7b 100644
--- a/sw/host/opentitantool/src/backend/mod.rs
+++ b/sw/host/opentitantool/src/backend/mod.rs
@@ -41,7 +41,7 @@
     match args.interface.as_str() {
         "" => Ok(Box::new(EmptyTransport)),
         "verilator" => verilator::create(&args.verilator_opts),
-        "ultradebug" => ultradebug::create(&args),
+        "ultradebug" => ultradebug::create(args),
         _ => Err(Error::UnknownInterface(args.interface.clone()).into()),
     }
 }
diff --git a/sw/host/opentitantool/src/command/console.rs b/sw/host/opentitantool/src/command/console.rs
index 037dfbb..6695305 100644
--- a/sw/host/opentitantool/src/command/console.rs
+++ b/sw/host/opentitantool/src/command/console.rs
@@ -161,7 +161,7 @@
                 if len == 1 && buf[0] == InnerConsole::CTRL_C {
                     break;
                 }
-                uart.write(&buf[..len])?;
+                uart.write_all(&buf[..len])?;
             }
         }
         Ok(())
@@ -169,7 +169,7 @@
 
     // Maintain a buffer for the exit regexes to match against.
     fn append_buffer(&mut self, data: &[u8]) {
-        self.buffer.push_str(&String::from_utf8_lossy(&data[..]));
+        self.buffer.push_str(&String::from_utf8_lossy(data));
         if self.buffer.len() > InnerConsole::BUFFER_LEN {
             let (_, end) = self
                 .buffer
diff --git a/sw/host/opentitantool/src/command/gpio.rs b/sw/host/opentitantool/src/command/gpio.rs
index f3ccde2..3adaeb1 100644
--- a/sw/host/opentitantool/src/command/gpio.rs
+++ b/sw/host/opentitantool/src/command/gpio.rs
@@ -29,7 +29,7 @@
         let value = gpio.read(self.pin)?;
         Ok(Some(Box::new(GpioReadResult {
             pin: self.pin,
-            value: value,
+            value,
         })))
     }
 }
diff --git a/sw/host/opentitantool/src/command/spi.rs b/sw/host/opentitantool/src/command/spi.rs
index b94a1b7..7f56a7d 100644
--- a/sw/host/opentitantool/src/command/spi.rs
+++ b/sw/host/opentitantool/src/command/spi.rs
@@ -141,9 +141,9 @@
 impl SpiRead {
     fn write_file(&self, mut writer: impl Write, buffer: &[u8]) -> Result<()> {
         if self.hexdump {
-            hexdump(writer, &buffer)?;
+            hexdump(writer, buffer)?;
         } else {
-            writer.write_all(&buffer)?;
+            writer.write_all(buffer)?;
         }
         Ok(())
     }