From 9806d83e7c6ca69df4f92872f2fdf67ec3ac2e70 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 16 Nov 2022 22:02:37 +0000 Subject: [PATCH] devices: modify safety comments Signed-off-by: Wei Liu --- devices/src/legacy/cmos.rs | 2 +- devices/src/legacy/rtc_pl031.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/devices/src/legacy/cmos.rs b/devices/src/legacy/cmos.rs index 4ccb396d6..b6ac3bace 100644 --- a/devices/src/legacy/cmos.rs +++ b/devices/src/legacy/cmos.rs @@ -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 { diff --git a/devices/src/legacy/rtc_pl031.rs b/devices/src/legacy/rtc_pl031.rs index b07b009e1..27ae60a1c 100644 --- a/devices/src/legacy/rtc_pl031.rs +++ b/devices/src/legacy/rtc_pl031.rs @@ -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(×pec.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) }