Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit dd5dd89

Browse files
committed
Run cargo clippy from inside Kbuild
Once we do #191, build.rs needs to run inside Kbuild (since it can no longer call out to kernel-cflags-finder), and clippy is unable to run if build.rs doesn't run. Also, fix up clippy warnings about our actual modules, not just the framework.
1 parent 240393d commit dd5dd89

File tree

8 files changed

+12
-16
lines changed

8 files changed

+12
-16
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ script:
2323
(cd "$p" && cargo fmt --all -- --check) || exit 1
2424
fi
2525
done
26-
- cargo clippy -- -D warnings
2726
2827
after_failure:
2928
- dmesg

hello-world/Kbuild

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ helloworld-objs := hello_world.rust.o
44
CARGO ?= cargo
55

66
$(src)/target/x86_64-linux-kernel/debug/libhello_world.a: $(src)/Cargo.toml $(wildcard $(src)/src/*.rs)
7-
cd $(src); env -u MAKE -u MAKEFLAGS $(CARGO) build -Z build-std=core,alloc --target=x86_64-linux-kernel
7+
cd $(src); $(CARGO) build -Z build-std=core,alloc --target=x86_64-linux-kernel
88

99
%.rust.o: target/x86_64-linux-kernel/debug/lib%.a
1010
$(LD) -r -o $@ --whole-archive $<

hello-world/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ extern crate alloc;
55
use alloc::borrow::ToOwned;
66
use alloc::string::String;
77

8-
use linux_kernel_module;
98
use linux_kernel_module::println;
109

1110
struct HelloWorldModule {

tests/Kbuild

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ testmodule-objs := $(TEST_NAME).rust.o
44
CARGO ?= cargo
55

66
$(src)/target/x86_64-linux-kernel/debug/lib%.a: $(src)/$(TEST_PATH)/Cargo.toml $(wildcard $(src)/$(TEST_PATH)/src/*.rs)
7-
cd $(src)/$(TEST_PATH); env -u MAKE -u MAKEFLAGS CARGO_TARGET_DIR=../target $(CARGO) build -Z build-std=core,alloc --target=x86_64-linux-kernel
7+
cd $(src)/$(TEST_PATH); CARGO_TARGET_DIR=../target $(CARGO) build -Z build-std=core,alloc --target=x86_64-linux-kernel
8+
cd $(src)/$(TEST_PATH); CARGO_TARGET_DIR=../target $(CARGO) clippy -Z build-std=core,alloc --target=x86_64-linux-kernel -- -Dwarnings
89

910
%.rust.o: target/x86_64-linux-kernel/debug/lib%.a
1011
$(LD) -r -o $@ --whole-archive $<

tests/chrdev/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl linux_kernel_module::file_operations::FileOperations for CycleFile {
1616
.build();
1717

1818
fn open() -> linux_kernel_module::KernelResult<Self> {
19-
return Ok(CycleFile);
19+
Ok(CycleFile)
2020
}
2121
}
2222
impl linux_kernel_module::file_operations::Read for CycleFile {
@@ -34,7 +34,7 @@ impl linux_kernel_module::file_operations::Read for CycleFile {
3434
{
3535
buf.write(&[*c])?;
3636
}
37-
return Ok(());
37+
Ok(())
3838
}
3939
}
4040

@@ -47,7 +47,7 @@ impl linux_kernel_module::file_operations::FileOperations for SeekFile {
4747
.build();
4848

4949
fn open() -> linux_kernel_module::KernelResult<Self> {
50-
return Ok(SeekFile);
50+
Ok(SeekFile)
5151
}
5252
}
5353

@@ -57,7 +57,7 @@ impl linux_kernel_module::file_operations::Seek for SeekFile {
5757
_file: &linux_kernel_module::file_operations::File,
5858
_offset: linux_kernel_module::file_operations::SeekFrom,
5959
) -> linux_kernel_module::KernelResult<u64> {
60-
return Ok(1234);
60+
Ok(1234)
6161
}
6262
}
6363

@@ -73,9 +73,9 @@ impl linux_kernel_module::file_operations::FileOperations for WriteFile {
7373
.build();
7474

7575
fn open() -> linux_kernel_module::KernelResult<Self> {
76-
return Ok(WriteFile {
76+
Ok(WriteFile {
7777
written: AtomicUsize::new(0),
78-
});
78+
})
7979
}
8080
}
8181

@@ -88,7 +88,7 @@ impl linux_kernel_module::file_operations::Read for WriteFile {
8888
) -> linux_kernel_module::KernelResult<()> {
8989
let val = self.written.load(Ordering::SeqCst).to_string();
9090
buf.write(val.as_bytes())?;
91-
return Ok(());
91+
Ok(())
9292
}
9393
}
9494

@@ -100,7 +100,7 @@ impl linux_kernel_module::file_operations::Write for WriteFile {
100100
) -> linux_kernel_module::KernelResult<()> {
101101
let data = buf.read_all()?;
102102
self.written.fetch_add(data.len(), Ordering::SeqCst);
103-
return Ok(());
103+
Ok(())
104104
}
105105
}
106106

tests/modinfo/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![no_std]
22

3-
use linux_kernel_module;
4-
53
struct ModinfoTestModule;
64

75
impl linux_kernel_module::KernelModule for ModinfoTestModule {

tests/printk/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![no_std]
2+
#![allow(clippy::print_literal)]
23

34
use linux_kernel_module::{self, println};
45

tests/utils/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![no_std]
22

3-
use linux_kernel_module;
4-
53
struct UtilsTestModule;
64

75
#[allow(dead_code)]

0 commit comments

Comments
 (0)