summary refs log tree commit diff
path: root/gpu_buffer
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2018-12-01 17:49:30 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-12-03 20:32:03 -0800
commit5bbbf610828e975fd308b90543359a85ef59b67f (patch)
tree4cd736628475d702b7ac45feb2e359c3fb74d220 /gpu_buffer
parent21fb34fb937678d85e9bfa4c721ab4a29196c764 (diff)
downloadcrosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar
crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.gz
crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.bz2
crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.lz
crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.xz
crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.zst
crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.zip
lint: Resolve the easier clippy lints
Hopefully the changes are self-explanatory and uncontroversial. This
eliminates much of the noise from `cargo clippy` and, for my purposes,
gives me a reasonable way to use it as a tool when writing and reviewing
code.

Here is the Clippy invocation I was using:

    cargo +nightly clippy -- -W clippy::correctness -A renamed_and_removed_lints -Aclippy::{blacklisted_name,borrowed_box,cast_lossless,cast_ptr_alignment,enum_variant_names,identity_op,if_same_then_else,mut_from_ref,needless_pass_by_value,new_without_default,new_without_default_derive,or_fun_call,ptr_arg,should_implement_trait,single_match,too_many_arguments,trivially_copy_pass_by_ref,unreadable_literal,unsafe_vector_initialization,useless_transmute}

TEST=cargo check --features wl-dmabuf,gpu,usb-emulation
TEST=boot linux

Change-Id: I55eb1b4a72beb2f762480e3333a921909314a0a2
Reviewed-on: https://chromium-review.googlesource.com/1356911
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'gpu_buffer')
-rw-r--r--gpu_buffer/src/lib.rs25
-rw-r--r--gpu_buffer/src/rendernode.rs2
2 files changed, 10 insertions, 17 deletions
diff --git a/gpu_buffer/src/lib.rs b/gpu_buffer/src/lib.rs
index e57053d..ad8dd63 100644
--- a/gpu_buffer/src/lib.rs
+++ b/gpu_buffer/src/lib.rs
@@ -236,7 +236,7 @@ impl Format {
             DRM_FORMAT_XRGB8888 => 4,
             _ => return None,
         };
-        return Some(bpp);
+        Some(bpp)
     }
 }
 
@@ -576,10 +576,10 @@ impl Buffer {
                 let line_offset = checked_arithmetic!(yy * stride)?;
                 let src_line = src
                     .get_slice(line_offset, line_copy_size)
-                    .map_err(|e| Error::Memcopy(e))?;
+                    .map_err(Error::Memcopy)?;
                 let dst_line = dst
                     .get_slice(line_offset, line_copy_size)
-                    .map_err(|e| Error::Memcopy(e))?;
+                    .map_err(Error::Memcopy)?;
                 src_line.copy_to_volatile_slice(dst_line);
             }
         }
@@ -627,13 +627,11 @@ impl Buffer {
                 let copy_sg_size = min(sg_size, copy_size);
                 let src_slice = sg
                     .get_slice(src_offset, copy_sg_size)
-                    .map_err(|e| Error::Memcopy(e))?;
+                    .map_err(Error::Memcopy)?;
                 src_slice.copy_to_volatile_slice(dst_slice);
 
                 src_offset = 0;
-                dst_slice = dst_slice
-                    .offset(copy_sg_size)
-                    .map_err(|e| Error::Memcopy(e))?;
+                dst_slice = dst_slice.offset(copy_sg_size).map_err(Error::Memcopy)?;
                 copy_size -= copy_sg_size;
                 if copy_size == 0 {
                     break;
@@ -647,8 +645,7 @@ impl Buffer {
             let line_end_skip = checked_arithmetic!(stride - line_copy_size)?;
             let mut remaining_line_copy_size = line_copy_size;
             let mut sg_opt = sgs.next();
-            while !sg_opt.is_none() {
-                let sg = sg_opt.unwrap();
+            while let Some(sg) = sg_opt {
                 // Skip src_offset into this scatter gather item, or the entire thing if offset is
                 // larger.
                 let sg_size = match sg.size().checked_sub(src_offset) {
@@ -662,13 +659,11 @@ impl Buffer {
                 let copy_sg_size = min(sg_size, remaining_line_copy_size);
                 let src_slice = sg
                     .get_slice(src_offset, copy_sg_size)
-                    .map_err(|e| Error::Memcopy(e))?;
+                    .map_err(Error::Memcopy)?;
                 src_slice.copy_to_volatile_slice(dst_slice);
 
                 src_offset += copy_sg_size;
-                dst_slice = dst_slice
-                    .offset(copy_sg_size)
-                    .map_err(|e| Error::Memcopy(e))?;
+                dst_slice = dst_slice.offset(copy_sg_size).map_err(Error::Memcopy)?;
                 remaining_line_copy_size -= copy_sg_size;
                 if remaining_line_copy_size == 0 {
                     remaining_line_copy_size = line_copy_size;
@@ -678,9 +673,7 @@ impl Buffer {
                     }
 
                     src_offset += line_end_skip;
-                    dst_slice = dst_slice
-                        .offset(line_end_skip)
-                        .map_err(|e| Error::Memcopy(e))?;
+                    dst_slice = dst_slice.offset(line_end_skip).map_err(Error::Memcopy)?;
                 }
             }
         }
diff --git a/gpu_buffer/src/rendernode.rs b/gpu_buffer/src/rendernode.rs
index 2c4c51b..b9849e0 100644
--- a/gpu_buffer/src/rendernode.rs
+++ b/gpu_buffer/src/rendernode.rs
@@ -88,7 +88,7 @@ pub fn open_device(undesired: &[&str]) -> Result<File, ()> {
     const DRM_MAX_MINOR: u32 = 15;
     const RENDER_NODE_START: u32 = 128;
 
-    for n in RENDER_NODE_START..(RENDER_NODE_START + DRM_MAX_MINOR + 1) {
+    for n in RENDER_NODE_START..=RENDER_NODE_START + DRM_MAX_MINOR {
         let path = Path::new(DRM_DIR_NAME).join(format!("renderD{}", n));
 
         if let Ok(fd) = OpenOptions::new().read(true).write(true).open(path) {