Skip to content

Commit b0a86fb

Browse files
Herculoxzvireshk
authored andcommitted
rust: cpufreq: use c_ types from kernel prelude
Update cpufreq FFI callback signatures to use `c_int` from the `kernel::prelude`, rather than accessing it explicitly through `kernel::ffi::c_int`. Although these types are defined in the `ffi` crate, they are re-exported via `kernel::prelude`. This aligns with the Rust-for-Linux coding guidelines and ensures proper C ABI compatibility across platforms. Signed-off-by: Abhinav Ananthu <abhinav.ogl@gmail.com> Suggested-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> [ Viresh: Fixed rustfmtcheck errors ] Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 10bb7f0 commit b0a86fb

1 file changed

Lines changed: 15 additions & 23 deletions

File tree

rust/kernel/cpufreq.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ impl<T: Driver> Registration<T> {
10611061
///
10621062
/// - This function may only be called from the cpufreq C infrastructure.
10631063
/// - The pointer arguments must be valid pointers.
1064-
unsafe extern "C" fn init_callback(ptr: *mut bindings::cpufreq_policy) -> kernel::ffi::c_int {
1064+
unsafe extern "C" fn init_callback(ptr: *mut bindings::cpufreq_policy) -> c_int {
10651065
from_result(|| {
10661066
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
10671067
// lifetime of `policy`.
@@ -1094,7 +1094,7 @@ impl<T: Driver> Registration<T> {
10941094
///
10951095
/// - This function may only be called from the cpufreq C infrastructure.
10961096
/// - The pointer arguments must be valid pointers.
1097-
unsafe extern "C" fn online_callback(ptr: *mut bindings::cpufreq_policy) -> kernel::ffi::c_int {
1097+
unsafe extern "C" fn online_callback(ptr: *mut bindings::cpufreq_policy) -> c_int {
10981098
from_result(|| {
10991099
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
11001100
// lifetime of `policy`.
@@ -1109,9 +1109,7 @@ impl<T: Driver> Registration<T> {
11091109
///
11101110
/// - This function may only be called from the cpufreq C infrastructure.
11111111
/// - The pointer arguments must be valid pointers.
1112-
unsafe extern "C" fn offline_callback(
1113-
ptr: *mut bindings::cpufreq_policy,
1114-
) -> kernel::ffi::c_int {
1112+
unsafe extern "C" fn offline_callback(ptr: *mut bindings::cpufreq_policy) -> c_int {
11151113
from_result(|| {
11161114
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
11171115
// lifetime of `policy`.
@@ -1126,9 +1124,7 @@ impl<T: Driver> Registration<T> {
11261124
///
11271125
/// - This function may only be called from the cpufreq C infrastructure.
11281126
/// - The pointer arguments must be valid pointers.
1129-
unsafe extern "C" fn suspend_callback(
1130-
ptr: *mut bindings::cpufreq_policy,
1131-
) -> kernel::ffi::c_int {
1127+
unsafe extern "C" fn suspend_callback(ptr: *mut bindings::cpufreq_policy) -> c_int {
11321128
from_result(|| {
11331129
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
11341130
// lifetime of `policy`.
@@ -1143,7 +1139,7 @@ impl<T: Driver> Registration<T> {
11431139
///
11441140
/// - This function may only be called from the cpufreq C infrastructure.
11451141
/// - The pointer arguments must be valid pointers.
1146-
unsafe extern "C" fn resume_callback(ptr: *mut bindings::cpufreq_policy) -> kernel::ffi::c_int {
1142+
unsafe extern "C" fn resume_callback(ptr: *mut bindings::cpufreq_policy) -> c_int {
11471143
from_result(|| {
11481144
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
11491145
// lifetime of `policy`.
@@ -1171,9 +1167,7 @@ impl<T: Driver> Registration<T> {
11711167
///
11721168
/// - This function may only be called from the cpufreq C infrastructure.
11731169
/// - The pointer arguments must be valid pointers.
1174-
unsafe extern "C" fn verify_callback(
1175-
ptr: *mut bindings::cpufreq_policy_data,
1176-
) -> kernel::ffi::c_int {
1170+
unsafe extern "C" fn verify_callback(ptr: *mut bindings::cpufreq_policy_data) -> c_int {
11771171
from_result(|| {
11781172
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
11791173
// lifetime of `policy`.
@@ -1188,9 +1182,7 @@ impl<T: Driver> Registration<T> {
11881182
///
11891183
/// - This function may only be called from the cpufreq C infrastructure.
11901184
/// - The pointer arguments must be valid pointers.
1191-
unsafe extern "C" fn setpolicy_callback(
1192-
ptr: *mut bindings::cpufreq_policy,
1193-
) -> kernel::ffi::c_int {
1185+
unsafe extern "C" fn setpolicy_callback(ptr: *mut bindings::cpufreq_policy) -> c_int {
11941186
from_result(|| {
11951187
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
11961188
// lifetime of `policy`.
@@ -1209,7 +1201,7 @@ impl<T: Driver> Registration<T> {
12091201
ptr: *mut bindings::cpufreq_policy,
12101202
target_freq: c_uint,
12111203
relation: c_uint,
1212-
) -> kernel::ffi::c_int {
1204+
) -> c_int {
12131205
from_result(|| {
12141206
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
12151207
// lifetime of `policy`.
@@ -1227,7 +1219,7 @@ impl<T: Driver> Registration<T> {
12271219
unsafe extern "C" fn target_index_callback(
12281220
ptr: *mut bindings::cpufreq_policy,
12291221
index: c_uint,
1230-
) -> kernel::ffi::c_int {
1222+
) -> c_int {
12311223
from_result(|| {
12321224
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
12331225
// lifetime of `policy`.
@@ -1250,7 +1242,7 @@ impl<T: Driver> Registration<T> {
12501242
unsafe extern "C" fn fast_switch_callback(
12511243
ptr: *mut bindings::cpufreq_policy,
12521244
target_freq: c_uint,
1253-
) -> kernel::ffi::c_uint {
1245+
) -> c_uint {
12541246
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
12551247
// lifetime of `policy`.
12561248
let policy = unsafe { Policy::from_raw_mut(ptr) };
@@ -1285,7 +1277,7 @@ impl<T: Driver> Registration<T> {
12851277
unsafe extern "C" fn get_intermediate_callback(
12861278
ptr: *mut bindings::cpufreq_policy,
12871279
index: c_uint,
1288-
) -> kernel::ffi::c_uint {
1280+
) -> c_uint {
12891281
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
12901282
// lifetime of `policy`.
12911283
let policy = unsafe { Policy::from_raw_mut(ptr) };
@@ -1306,7 +1298,7 @@ impl<T: Driver> Registration<T> {
13061298
unsafe extern "C" fn target_intermediate_callback(
13071299
ptr: *mut bindings::cpufreq_policy,
13081300
index: c_uint,
1309-
) -> kernel::ffi::c_int {
1301+
) -> c_int {
13101302
from_result(|| {
13111303
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
13121304
// lifetime of `policy`.
@@ -1325,7 +1317,7 @@ impl<T: Driver> Registration<T> {
13251317
/// # Safety
13261318
///
13271319
/// - This function may only be called from the cpufreq C infrastructure.
1328-
unsafe extern "C" fn get_callback(cpu: c_uint) -> kernel::ffi::c_uint {
1320+
unsafe extern "C" fn get_callback(cpu: c_uint) -> c_uint {
13291321
// SAFETY: The C API guarantees that `cpu` refers to a valid CPU number.
13301322
let cpu_id = unsafe { CpuId::from_u32_unchecked(cpu) };
13311323

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

@@ -1372,7 +1364,7 @@ impl<T: Driver> Registration<T> {
13721364
unsafe extern "C" fn set_boost_callback(
13731365
ptr: *mut bindings::cpufreq_policy,
13741366
state: c_int,
1375-
) -> kernel::ffi::c_int {
1367+
) -> c_int {
13761368
from_result(|| {
13771369
// SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the
13781370
// lifetime of `policy`.

0 commit comments

Comments
 (0)