Skip to contentSkip to conversation

cpufreq: rust: Use C FFI types in bios_limit_callback

PATCH In review Abhinav Ananthu 3 participants 4 messages Jun 12, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: rust: Use C FFI types in bios_limit_callback

Update the bios_limit_callback function to use C FFI-compatible types (kernel::ffi::c_int and kernel::ffi::c_uint) for its parameters and return value. This ensures ABI compatibility with the corresponding C callback signature.

---
 rust/kernel/cpufreq.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/cpufreq.rs +1 -1
index b0a9c6182aec..7ef2f64d8f34 100644
@@ -1277,7 +1277,7 @@ extern "C" fn update_limits_callback(ptr: *mut bindings::cpufreq_policy) {
     /// Driver's `bios_limit` callback.
     ///
     /// SAFETY: Called from C. Inputs must be valid pointers.
-    extern "C" fn bios_limit_callback(cpu: i32, limit: *mut u32) -> kernel::ffi::c_int {
+    extern "C" fn bios_limit_callback(cpu: kernel::ffi::c_int, limit: *mut kernel::ffi::c_uint) -> kernel::ffi::c_int {
         from_result(|| {
             let mut policy = PolicyCpu::from_cpu(cpu as u32)?;
 
Signature · 1 line
2.34.1
reviewer
#1 lore raw
Quoted 17 lines · Abhinav Ananthu

Update the bios_limit_callback function to use C FFI-compatible types (kernel::ffi::c_int and kernel::ffi::c_uint) for its parameters and return value. This ensures ABI compatibility with the corresponding C callback signature.

---
 rust/kernel/cpufreq.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/cpufreq.rs +0 -0
index b0a9c6182aec..7ef2f64d8f34 100644

rust/kernel/cpufreq.rs extern "C" fn update_limits_callback(ptr: *mut bindings::cpufreq_policy) { · line 1280

Quoted 5 lines
rust/kernel/cpufreq.rs +1 -1
@@ -1277,7 +1277,7 @@ extern "C" fn update_limits_callback(ptr: *mut bindings::cpufreq_policy) {
     /// Driver's `bios_limit` callback.
     ///
     /// SAFETY: Called from C. Inputs must be valid pointers.
-    extern "C" fn bios_limit_callback(cpu: i32, limit: *mut u32) -> kernel::ffi::c_int {
+    extern "C" fn bios_limit_callback(cpu: kernel::ffi::c_int, limit: *mut kernel::ffi::c_uint) -> kernel::ffi::c_int {

This file imports the kernel's prelude, so you should be able to just use c_int and c_uint instead of their qualified names.

---
Cheers,
Benno

Quoted 3 lines
rust/kernel/cpufreq.rs +0 -0
         from_result(|| {
             let mut policy = PolicyCpu::from_cpu(cpu as u32)?;
 
#2 lore raw

PATCH v2 1/1 fix : Update the bios_limit_callback to use

PATCH(v1)
Update the bios_limit_callback function to use C FFI-compatible types (kernel::ffi::c_int and kernel::ffi::c_uint) for its parameters and return value. This ensures ABI compatibility with the corresponding C callback signature.

PATCH(v2)
updated the bios_limit_callback function to use c_int and c_uint directly via the prelude instead of the fully-qualified kernel::ffi::* paths.

---
 rust/kernel/cpufreq.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/cpufreq.rs +1 -1
index b0a9c6182aec..e97607ed86c2 100644
@@ -1277,7 +1277,7 @@ extern "C" fn update_limits_callback(ptr: *mut bindings::cpufreq_policy) {
     /// Driver's `bios_limit` callback.
     ///
     /// SAFETY: Called from C. Inputs must be valid pointers.
-    extern "C" fn bios_limit_callback(cpu: i32, limit: *mut u32) -> kernel::ffi::c_int {
+    extern "C" fn bios_limit_callback(cpu: c_int, limit: *mut c_uint) -> c_int {
         from_result(|| {
             let mut policy = PolicyCpu::from_cpu(cpu as u32)?;
 
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCHv2 rust-for-linux] fix : Update the bios_limit_callback to use

Quoted 7 lines · Abhinav Ananthu

PATCH(v1)
Update the bios_limit_callback function to use C FFI-compatible types (kernel::ffi::c_int and kernel::ffi::c_uint) for its parameters and return value. This ensures ABI compatibility with the corresponding C callback signature.

Quoted 7 lines

PATCH(v2)
updated the bios_limit_callback function to use c_int and c_uint directly via the prelude instead of the fully-qualified kernel::ffi::* paths.

Cc'ing Viresh/Rafael/cpufreq, since this is on their subsystem (please see the entry in the MAINTAINERS file for rust/kernel/cpufreq.rs).

Also, please note that the changelog goes below the --- line. The commit message (above the --- line) should explain the "what" and the "why" of the current proposed changes, not other versions.

Finally, the title would normally have been something like:

    [PATCH v2] rust: cpufreq: ...

Thanks for the patch!

Cheers,
Miguel