Skip to content

Commit 10bb7f0

Browse files
Herculoxzvireshk
authored andcommitted
rust: cpufreq: Ensure C ABI compatibility in all unsafe
Update all `unsafe extern "C"` callback functions in the cpufreq module to use `kernel::ffi` types (`c_int`, `c_uint`, etc.) instead of Rust-native types like `i32`, `u32`, or `usize`. This change ensures that all Rust callbacks have signatures that are ABI-compatible with their corresponding C counterparts, which is critical for FFI correctness and safety. Suggested-by: Miguel Ojeda <ojeda@kernel.org> Link: Rust-for-Linux#1170 Signed-off-by: Abhinav Ananthu <abhinav.ogl@gmail.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 43ab245 commit 10bb7f0

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

rust/kernel/cpufreq.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,8 @@ impl<T: Driver> Registration<T> {
12071207
/// - The pointer arguments must be valid pointers.
12081208
unsafe extern "C" fn target_callback(
12091209
ptr: *mut bindings::cpufreq_policy,
1210-
target_freq: u32,
1211-
relation: u32,
1210+
target_freq: c_uint,
1211+
relation: c_uint,
12121212
) -> kernel::ffi::c_int {
12131213
from_result(|| {
12141214
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
@@ -1226,7 +1226,7 @@ impl<T: Driver> Registration<T> {
12261226
/// - The pointer arguments must be valid pointers.
12271227
unsafe extern "C" fn target_index_callback(
12281228
ptr: *mut bindings::cpufreq_policy,
1229-
index: u32,
1229+
index: c_uint,
12301230
) -> kernel::ffi::c_int {
12311231
from_result(|| {
12321232
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
@@ -1249,7 +1249,7 @@ impl<T: Driver> Registration<T> {
12491249
/// - The pointer arguments must be valid pointers.
12501250
unsafe extern "C" fn fast_switch_callback(
12511251
ptr: *mut bindings::cpufreq_policy,
1252-
target_freq: u32,
1252+
target_freq: c_uint,
12531253
) -> kernel::ffi::c_uint {
12541254
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
12551255
// lifetime of `policy`.
@@ -1263,10 +1263,10 @@ impl<T: Driver> Registration<T> {
12631263
///
12641264
/// - This function may only be called from the cpufreq C infrastructure.
12651265
unsafe extern "C" fn adjust_perf_callback(
1266-
cpu: u32,
1267-
min_perf: usize,
1268-
target_perf: usize,
1269-
capacity: usize,
1266+
cpu: c_uint,
1267+
min_perf: c_ulong,
1268+
target_perf: c_ulong,
1269+
capacity: c_ulong,
12701270
) {
12711271
// SAFETY: The C API guarantees that `cpu` refers to a valid CPU number.
12721272
let cpu_id = unsafe { CpuId::from_u32_unchecked(cpu) };
@@ -1284,7 +1284,7 @@ impl<T: Driver> Registration<T> {
12841284
/// - The pointer arguments must be valid pointers.
12851285
unsafe extern "C" fn get_intermediate_callback(
12861286
ptr: *mut bindings::cpufreq_policy,
1287-
index: u32,
1287+
index: c_uint,
12881288
) -> kernel::ffi::c_uint {
12891289
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
12901290
// lifetime of `policy`.
@@ -1305,7 +1305,7 @@ impl<T: Driver> Registration<T> {
13051305
/// - The pointer arguments must be valid pointers.
13061306
unsafe extern "C" fn target_intermediate_callback(
13071307
ptr: *mut bindings::cpufreq_policy,
1308-
index: u32,
1308+
index: c_uint,
13091309
) -> kernel::ffi::c_int {
13101310
from_result(|| {
13111311
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
@@ -1325,7 +1325,7 @@ impl<T: Driver> Registration<T> {
13251325
/// # Safety
13261326
///
13271327
/// - This function may only be called from the cpufreq C infrastructure.
1328-
unsafe extern "C" fn get_callback(cpu: u32) -> kernel::ffi::c_uint {
1328+
unsafe extern "C" fn get_callback(cpu: c_uint) -> kernel::ffi::c_uint {
13291329
// SAFETY: The C API guarantees that `cpu` refers to a valid CPU number.
13301330
let cpu_id = unsafe { CpuId::from_u32_unchecked(cpu) };
13311331

@@ -1351,7 +1351,7 @@ impl<T: Driver> Registration<T> {
13511351
///
13521352
/// - This function may only be called from the cpufreq C infrastructure.
13531353
/// - The pointer arguments must be valid pointers.
1354-
unsafe extern "C" fn bios_limit_callback(cpu: i32, limit: *mut u32) -> kernel::ffi::c_int {
1354+
unsafe extern "C" fn bios_limit_callback(cpu: c_int, limit: *mut c_uint) -> kernel::ffi::c_int {
13551355
// SAFETY: The C API guarantees that `cpu` refers to a valid CPU number.
13561356
let cpu_id = unsafe { CpuId::from_i32_unchecked(cpu) };
13571357

@@ -1371,7 +1371,7 @@ impl<T: Driver> Registration<T> {
13711371
/// - The pointer arguments must be valid pointers.
13721372
unsafe extern "C" fn set_boost_callback(
13731373
ptr: *mut bindings::cpufreq_policy,
1374-
state: i32,
1374+
state: c_int,
13751375
) -> kernel::ffi::c_int {
13761376
from_result(|| {
13771377
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the

0 commit comments

Comments
 (0)