devices: modify safety comments

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2022-11-16 22:02:37 +00:00 committed by Liu Wei
parent f16b57716d
commit 9806d83e7c
2 changed files with 4 additions and 4 deletions

View File

@ -97,7 +97,7 @@ impl BusDevice for Cmos {
let day;
let month;
let year;
// The clock_gettime and gmtime_r calls are safe as long as the structs they are
// SAFETY: The clock_gettime and gmtime_r calls are safe as long as the structs they are
// given are large enough, and neither of them fail. It is safe to zero initialize
// the tm and timespec struct because it contains only plain data.
let update_in_progress = unsafe {

View File

@ -121,7 +121,7 @@ impl LocalTime {
tm_zone: std::ptr::null(),
};
// Safe because the parameters are valid.
// SAFETY: the parameters are valid.
unsafe {
libc::clock_gettime(libc::CLOCK_REALTIME, &mut timespec);
libc::localtime_r(&timespec.tv_sec, &mut tm);
@ -179,7 +179,7 @@ impl Default for TimestampUs {
#[allow(dead_code)]
pub fn timestamp_cycles() -> u64 {
#[cfg(target_arch = "x86_64")]
// Safe because there's nothing that can go wrong with this call.
// SAFETY: there's nothing that can go wrong with this call.
unsafe {
std::arch::x86_64::_rdtsc() as u64
}
@ -199,7 +199,7 @@ pub fn get_time(clock_type: ClockType) -> u64 {
tv_sec: 0,
tv_nsec: 0,
};
// Safe because the parameters are valid.
// SAFETY: the parameters are valid.
unsafe { libc::clock_gettime(clock_type.into(), &mut time_struct) };
seconds_to_nanoseconds(time_struct.tv_sec).unwrap() as u64 + (time_struct.tv_nsec as u64)
}