Skip to content

Commit 054ec74

Browse files
committed
clippy: use if let Some()
Signed-off-by: Krishnan Winter <krishnan.winter@unsw.edu.au>
1 parent 5c536ac commit 054ec74

2 files changed

Lines changed: 19 additions & 30 deletions

File tree

tool/microkit/src/capdl/builder.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -700,19 +700,16 @@ pub fn build_capdl_spec(
700700
));
701701

702702
// Step 3-5 Create fault Endpoint cap to parent/monitor
703-
let pd_fault_ep_cap = if pd.parent.is_none() {
704-
let badge: u64 = mon_pd_idx as u64 + 1;
705-
capdl_util_make_endpoint_cap(mon_fault_ep_obj_id, true, true, true, badge)
706-
} else {
703+
let pd_fault_ep_cap = if let Some(parent) = pd.parent {
707704
// @kwinter: Should we enforce domain boundaries here?
708-
assert!(pd_global_idx > pd.parent.unwrap());
705+
assert!(pd_global_idx > parent);
709706
let badge: u64 = FAULT_BADGE | pd.id.unwrap();
710-
let parent_ep_obj_id = &pd_id_to_ep_id[&pd.parent.unwrap()];
707+
let parent_ep_obj_id = &pd_id_to_ep_id[&parent];
711708
let fault_ep_cap =
712709
capdl_util_make_endpoint_cap(*parent_ep_obj_id, true, true, true, badge);
713710

714711
// Allow the parent PD to access the child's TCB:
715-
let parent_cspace_obj_id = &pd_id_to_cspace_id[&pd.parent.unwrap()];
712+
let parent_cspace_obj_id = &pd_id_to_cspace_id[&parent];
716713
capdl_util_insert_cap_into_cspace(
717714
&mut spec_container,
718715
*parent_cspace_obj_id,
@@ -721,7 +718,11 @@ pub fn build_capdl_spec(
721718
);
722719

723720
fault_ep_cap
721+
} else {
722+
let badge: u64 = mon_pd_idx as u64 + 1;
723+
capdl_util_make_endpoint_cap(mon_fault_ep_obj_id, true, true, true, badge)
724724
};
725+
725726
caps_to_insert_to_pd_cspace.push(capdl_util_make_cte(
726727
PD_FAULT_EP_CAP_IDX as u32,
727728
pd_fault_ep_cap.clone(),
@@ -1125,38 +1126,28 @@ pub fn build_capdl_spec(
11251126
// Step 5. Parse domain schedule
11261127
// *********************************
11271128

1128-
if system.domain_schedule.is_some() {
1129+
if let Some(sys_domain_schedule) = &system.domain_schedule {
11291130
let mut domain_schedule: Vec<DomainSchedEntry> = Vec::new();
11301131
// We want to convert from the microseconds that the user defines in the
11311132
// sdf to the kernel scheduler ticks. If we are on x86, we won't necessarily
11321133
// have a static definition of the timer frequency. We will express the
11331134
// domain timeslices in ticks.
1134-
let ticks_in_ms = if kernel_config.timer_freq.is_some() {
1135-
kernel_config.timer_freq.unwrap() / US_IN_S
1135+
let ticks_in_ms = if let Some(timer_freq) = kernel_config.timer_freq {
1136+
timer_freq / US_IN_S
11361137
} else {
11371138
1
11381139
};
11391140

1140-
for sched_entry in system.domain_schedule.as_ref().unwrap().schedule.iter() {
1141+
for sched_entry in sys_domain_schedule.schedule.iter() {
11411142
domain_schedule.push(DomainSchedEntry {
11421143
id: sched_entry.id,
11431144
time: sched_entry.length * ticks_in_ms,
11441145
});
11451146
}
11461147

11471148
spec_container.spec.domain_schedule = Some(domain_schedule);
1148-
spec_container.spec.domain_set_start = system
1149-
.domain_schedule
1150-
.as_ref()
1151-
.unwrap()
1152-
.domain_start_idx
1153-
.map(Word);
1154-
spec_container.spec.domain_idx_shift = system
1155-
.domain_schedule
1156-
.as_ref()
1157-
.unwrap()
1158-
.domain_idx_shift
1159-
.map(Word);
1149+
spec_container.spec.domain_set_start = sys_domain_schedule.domain_start_idx.map(Word);
1150+
spec_container.spec.domain_idx_shift = sys_domain_schedule.domain_idx_shift.map(Word);
11601151
}
11611152

11621153
// *********************************

tool/microkit/src/sdf.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,10 @@ impl DomainSchedule {
11831183
});
11841184
}
11851185
"domain_start" => {
1186-
if domain_start_idx.is_some() {
1186+
if let Some(domain_start_idx) = domain_start_idx {
11871187
return Err(format!(
11881188
"Error: Duplicate setting of domain start index, already set to '{}'",
1189-
domain_start_idx.unwrap()
1189+
domain_start_idx
11901190
));
11911191
}
11921192
check_attributes(xml_sdf, &child, &["index"])?;
@@ -1197,10 +1197,10 @@ impl DomainSchedule {
11971197
domain_start_idx = Some(start_index.unwrap());
11981198
}
11991199
"domain_idx_shift" => {
1200-
if domain_idx_shift.is_some() {
1200+
if let Some(domain_idx_shift) = domain_idx_shift {
12011201
return Err(format!(
12021202
"Error: Duplicate setting of domain index shift, already set to '{}'",
1203-
domain_idx_shift.unwrap()
1203+
domain_idx_shift
12041204
));
12051205
}
12061206
check_attributes(xml_sdf, &child, &["shift"])?;
@@ -2185,9 +2185,7 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
21852185
}
21862186

21872187
// Ensure that the domain start index (if supplied) points to a valid index
2188-
if domain_schedule.is_some() {
2189-
let dom_sched = domain_schedule.as_ref().unwrap();
2190-
2188+
if let Some(dom_sched) = &domain_schedule {
21912189
// Make sure we account for the shift when checking if the length of the
21922190
// schedule is valid and if the start index is valid.
21932191
let dom_shift = dom_sched.domain_idx_shift.unwrap_or(0);

0 commit comments

Comments
 (0)