summaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/cpufreq.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
index affa2b9490ef..b75d692846a2 100644
--- a/rust/kernel/cpufreq.rs
+++ b/rust/kernel/cpufreq.rs
@@ -14,7 +14,13 @@ use crate::{
cpumask,
device::{Bound, Device},
devres,
- error::{code::*, from_err_ptr, from_result, to_result, Result, VTABLE_DEFAULT_ERROR},
+ error::{
+ code::*,
+ from_result,
+ to_result,
+ Result,
+ VTABLE_DEFAULT_ERROR, //
+ },
ffi::{c_char, c_ulong},
prelude::*,
types::ForeignOwnable,
@@ -29,7 +35,10 @@ use core::{
marker::PhantomData,
ops::{Deref, DerefMut},
pin::Pin,
- ptr,
+ ptr::{
+ self,
+ NonNull, //
+ },
};
use macros::vtable;
@@ -687,12 +696,13 @@ struct PolicyCpu<'a>(&'a mut Policy);
impl<'a> PolicyCpu<'a> {
fn from_cpu(cpu: CpuId) -> Result<Self> {
// SAFETY: It is safe to call `cpufreq_cpu_get` for any valid CPU.
- let ptr = from_err_ptr(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) })?;
+ let ptr =
+ NonNull::new(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) }).ok_or(ENODEV)?;
Ok(Self(
- // SAFETY: The `ptr` is guaranteed to be valid and remains valid for the lifetime of
- // the returned reference.
- unsafe { Policy::from_raw_mut(ptr) },
+ // SAFETY: `ptr` is non-NULL and `cpufreq_cpu_get()` took a reference on it, so it is
+ // valid for writing and remains valid for the lifetime of the returned reference.
+ unsafe { Policy::from_raw_mut(ptr.as_ptr()) },
))
}
}