Skip to content

Commit 5fa3915

Browse files
kernel: more cleanup
Signed-off-by: Anhad Singh <[email protected]>
1 parent 44588fb commit 5fa3915

File tree

10 files changed

+54
-60
lines changed

10 files changed

+54
-60
lines changed

src/aero_kernel/src/drivers/block/ide/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,10 @@ struct Ide {
197197

198198
impl PciDeviceHandle for Ide {
199199
fn handles(&self, vendor_id: Vendor, device_id: DeviceType) -> bool {
200-
match (vendor_id, device_id) {
201-
(Vendor::Intel, DeviceType::IdeController) => true,
202-
203-
_ => false,
204-
}
200+
matches!(
201+
(vendor_id, device_id),
202+
(Vendor::Intel, DeviceType::IdeController)
203+
)
205204
}
206205

207206
fn start(&self, header: &PciHeader, _offset_table: &mut OffsetPageTable) {

src/aero_kernel/src/fs/block/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl BlockDeviceInterface for PartitionBlockDevice {
373373
return None;
374374
}
375375

376-
self.write_dma(self.offset + sector, start, size)
376+
self.device.write_dma(self.offset + sector, start, size)
377377
}
378378

379379
fn read_dma(&self, sector: usize, start: PhysAddr, size: usize) -> Option<usize> {

src/aero_kernel/src/fs/file_table.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,8 @@ impl FileTable {
192192
pub fn get_handle(&self, fd: usize) -> Option<Arc<FileHandle>> {
193193
let files = self.0.read();
194194

195-
if let Some(file) = &files.get(fd) {
196-
if let Some(handle) = file {
197-
return Some(handle.clone());
198-
}
195+
if let Some(Some(handle)) = &files.get(fd) {
196+
return Some(handle.clone());
199197
}
200198

201199
None
@@ -204,14 +202,12 @@ impl FileTable {
204202
pub fn log(&self) {
205203
let files = self.0.read();
206204

207-
for handle in files.iter() {
208-
if let Some(handle) = handle {
209-
log::debug!(
210-
"file handle: (fd={}, path=`{}`)",
211-
handle.fd,
212-
handle.inode.absolute_path_str()
213-
)
214-
}
205+
for handle in files.iter().flatten() {
206+
log::debug!(
207+
"file handle: (fd={}, path=`{}`)",
208+
handle.fd,
209+
handle.inode.absolute_path_str()
210+
)
215211
}
216212
}
217213

@@ -297,16 +293,14 @@ impl FileTable {
297293
pub fn deep_clone(&self) -> Self {
298294
let files = self.0.read();
299295

300-
for file in files.iter() {
301-
if let Some(handle) = file {
302-
let flags = *handle.flags.read();
296+
for handle in files.iter().flatten() {
297+
let flags = *handle.flags.read();
303298

304-
handle
305-
.inode
306-
.inode()
307-
.open(flags, handle.clone())
308-
.expect("FileTable::clone: failed to open file");
309-
}
299+
handle
300+
.inode
301+
.inode()
302+
.open(flags, handle.clone())
303+
.expect("FileTable::clone: failed to open file");
310304
}
311305

312306
Self(RwLock::new(files.clone()))

src/aero_kernel/src/fs/pipe.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ impl INodeInterface for Pipe {
106106
}
107107

108108
fn poll(&self, table: Option<&mut PollTable>) -> super::Result<PollFlags> {
109-
table.map(|e| {
110-
e.insert(&self.readers);
111-
e.insert(&self.writers)
112-
});
109+
if let Some(table) = table {
110+
table.insert(&self.readers);
111+
table.insert(&self.writers);
112+
}
113113

114114
let mut flags = PollFlags::OUT;
115115

src/aero_kernel/src/fs/procfs.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,35 @@ fn get_cpuinfo_cached() -> &'static str {
4646

4747
let mut data = json!({ "processors": [] });
4848

49-
data.get_mut("processors")
49+
if let Some(processors) = data
50+
.get_mut("processors")
5051
.and_then(|processors| processors.as_array_mut())
51-
.map(|processors| {
52-
let mut cpu_info = vec![];
52+
{
53+
let mut cpu_info = vec![];
5354

54-
#[cfg(target_arch = "x86_64")]
55-
tls::for_cpu_info_cached(|info| {
56-
let mut processor = json!({});
55+
#[cfg(target_arch = "x86_64")]
56+
tls::for_cpu_info_cached(|info| {
57+
let mut processor = json!({});
5758

58-
processor["id"] = Value::Number(Number::from(info.cpuid));
59-
processor["fpu"] = Value::Bool(info.fpu);
59+
processor["id"] = Value::Number(Number::from(info.cpuid));
60+
processor["fpu"] = Value::Bool(info.fpu);
6061

61-
push_string_if_some(&mut processor, "brand", info.brand.clone());
62-
push_string_if_some(&mut processor, "vendor", info.vendor.clone());
62+
push_string_if_some(&mut processor, "brand", info.brand.clone());
63+
push_string_if_some(&mut processor, "vendor", info.vendor.clone());
6364

64-
processor["features"] = Value::Array(
65-
info.features
66-
.iter()
67-
.map(|feature| Value::String(feature.to_string()))
68-
.collect(),
69-
);
65+
processor["features"] = Value::Array(
66+
info.features
67+
.iter()
68+
.map(|feature| Value::String(feature.to_string()))
69+
.collect(),
70+
);
7071

71-
cpu_info.push(processor);
72-
});
73-
74-
*processors = cpu_info;
72+
cpu_info.push(processor);
7573
});
7674

75+
*processors = cpu_info;
76+
}
77+
7778
data.to_string()
7879
})
7980
}

src/aero_kernel/src/fs/ramfs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl INodeInterface for LockedRamINode {
236236
fn unlink(&self, name: &str) -> Result<()> {
237237
let mut this = self.0.write();
238238

239-
if let Some(_) = this.children.remove(name) {
239+
if this.children.remove(name).is_some() {
240240
Ok(())
241241
} else {
242242
Err(FileSystemError::EntryNotFound)
@@ -445,7 +445,7 @@ impl INodeInterface for LockedRamINode {
445445
{
446446
let this = self.0.read();
447447

448-
if this.children.iter().any(|(e, _)| e == &name) {
448+
if this.children.iter().any(|(e, _)| e == name) {
449449
return Err(FileSystemError::EntryExists);
450450
}
451451
}

src/aero_kernel/src/modules.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub enum ModuleType {
4545
#[derive(Debug)]
4646
#[repr(C)]
4747
pub struct Module {
48-
pub init: *const fn() -> (),
48+
pub init: *const (),
4949
pub ty: ModuleType,
5050
}
5151

@@ -59,7 +59,7 @@ macro_rules! module_init {
5959
#[used]
6060
#[link_section = ".kernel_modules.init"]
6161
static __MODULE_INIT: $crate::modules::Module = $crate::modules::Module {
62-
init: $init_function as *const fn() -> (),
62+
init: $init_function as *const (),
6363
ty: $ty,
6464
};
6565
};
@@ -102,7 +102,7 @@ pub(crate) fn init() {
102102
launched_fs = true;
103103
}
104104

105-
let init = core::mem::transmute::<*const fn() -> (), fn() -> ()>(module.init);
105+
let init = core::mem::transmute::<*const (), fn() -> ()>(module.init);
106106
init();
107107
}
108108
}

src/aero_kernel/src/userland/scheduler/round_robin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl RoundRobin {
123123
self.await_io().unwrap();
124124
} else if let Some(task) = queue.dead.pop_front() {
125125
task.update_state(TaskState::Zombie);
126-
task.into_zombie();
126+
task.make_zombie();
127127
}
128128
}
129129

src/aero_kernel/src/userland/signals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl SignalEntry {
158158
})
159159
}
160160

161-
pub fn into_sigaction(&self) -> SigAction {
161+
pub fn sigaction(&self) -> SigAction {
162162
let handler: usize = self.handler.into();
163163

164164
SigAction {
@@ -369,7 +369,7 @@ impl Signals {
369369
let mut signals = self.entries();
370370

371371
if let Some(old) = old {
372-
*old = signals[signal].into_sigaction();
372+
*old = signals[signal].sigaction();
373373
}
374374

375375
if let Some(handler) = handler {

src/aero_kernel/src/userland/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ impl Task {
657657
}
658658
}
659659

660-
pub(super) fn into_zombie(&self) {
660+
pub(super) fn make_zombie(&self) {
661661
self.detach();
662662
self.arch_task_mut().dealloc();
663663

0 commit comments

Comments
 (0)