rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] rust : Update the bios_limit_callback to use the C FFI types #1170
@ 2025-06-12 10:41 Abhinav Ananthu
  2025-06-12 11:55 ` Miguel Ojeda
  2025-06-13  3:08 ` Viresh Kumar
  0 siblings, 2 replies; 5+ messages in thread
From: Abhinav Ananthu @ 2025-06-12 10:41 UTC (permalink / raw)
  To: Rafael J . Wysocki, Viresh Kumar, Miguel Ojeda, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-pm, rust-for-linux, linux-kernel, Abhinav Ananthu

Update the `bios_limit_callback` function to use `c_int` and `c_uint` types,
which match the C ABI for the corresponding callback function. These types are
imported from the prelude.

This change ensures the Rust function signature exactly matches its expected
C counterpart, avoiding potential issues with type mismatches in the FFI
boundary.

Reported-by: Miguel Ojeda <ojeda@kernel.org>
Closes: https://lore.kernel.org/rust-for-linux/CANiq72=WpuGELzLbH-fxdOeJy9fiDFwatz6ynERDh=HP2z2MBw@mail.gmail.com/.
Signed-off-by: Abhinav Ananthu <abhinav.ogl@gmail.com>
---

 rust/kernel/cpufreq.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
index b0a9c6182aec..e97607ed86c2 100644
--- a/rust/kernel/cpufreq.rs
+++ b/rust/kernel/cpufreq.rs
@@ -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)?;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] rust : Update the bios_limit_callback to use the C FFI types #1170
@ 2025-06-12 10:42 Abhinav Ananthu
  2025-06-12 11:51 ` Miguel Ojeda
  0 siblings, 1 reply; 5+ messages in thread
From: Abhinav Ananthu @ 2025-06-12 10:42 UTC (permalink / raw)
  To: Rafael J . Wysocki, Viresh Kumar, Miguel Ojeda, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-pm, rust-for-linux, linux-kernel, Abhinav Ananthu

Update the `bios_limit_callback` function to use `c_int` and `c_uint` types,
which match the C ABI for the corresponding callback function. These types are
imported from the prelude.

This change ensures the Rust function signature exactly matches its expected
C counterpart, avoiding potential issues with type mismatches in the FFI
boundary.

Reported-by: Miguel Ojeda <ojeda@kernel.org>
Closes: https://lore.kernel.org/rust-for-linux/CANiq72=WpuGELzLbH-fxdOeJy9fiDFwatz6ynERDh=HP2z2MBw@mail.gmail.com/.
Signed-off-by: Abhinav Ananthu <abhinav.ogl@gmail.com>
---

 rust/kernel/cpufreq.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
index b0a9c6182aec..e97607ed86c2 100644
--- a/rust/kernel/cpufreq.rs
+++ b/rust/kernel/cpufreq.rs
@@ -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)?;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rust : Update the bios_limit_callback to use the C FFI types #1170
  2025-06-12 10:42 Abhinav Ananthu
@ 2025-06-12 11:51 ` Miguel Ojeda
  0 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2025-06-12 11:51 UTC (permalink / raw)
  To: Abhinav Ananthu
  Cc: Rafael J . Wysocki, Viresh Kumar, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-pm, rust-for-linux, linux-kernel

On Thu, Jun 12, 2025 at 12:43 PM Abhinav Ananthu <abhinav.ogl@gmail.com> wrote:
>
> Update the `bios_limit_callback` function to use `c_int` and `c_uint` types,
> which match the C ABI for the corresponding callback function. These types are
> imported from the prelude.
>
> This change ensures the Rust function signature exactly matches its expected
> C counterpart, avoiding potential issues with type mismatches in the FFI
> boundary.
>
> Reported-by: Miguel Ojeda <ojeda@kernel.org>
> Closes: https://lore.kernel.org/rust-for-linux/CANiq72=WpuGELzLbH-fxdOeJy9fiDFwatz6ynERDh=HP2z2MBw@mail.gmail.com/.
> Signed-off-by: Abhinav Ananthu <abhinav.ogl@gmail.com>

This seems to be a duplicate email.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rust : Update the bios_limit_callback to use the C FFI types #1170
  2025-06-12 10:41 [PATCH v2] rust : Update the bios_limit_callback to use the C FFI types #1170 Abhinav Ananthu
@ 2025-06-12 11:55 ` Miguel Ojeda
  2025-06-13  3:08 ` Viresh Kumar
  1 sibling, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2025-06-12 11:55 UTC (permalink / raw)
  To: Abhinav Ananthu
  Cc: Rafael J . Wysocki, Viresh Kumar, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-pm, rust-for-linux, linux-kernel

On Thu, Jun 12, 2025 at 12:42 PM Abhinav Ananthu <abhinav.ogl@gmail.com> wrote:
>
> This change ensures the Rust function signature exactly matches its expected
> C counterpart, avoiding potential issues with type mismatches in the FFI
> boundary.

I think this is more of a cleanup, since the types will be the same
anyway, which is why I suggested using "Suggested-by" and "Link"
instead:

Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://github.com/Rust-for-Linux/linux/issues/1170

The title is still not correct (misses "cpufreq: ") and it is very
rare to have issue IDs in the title ("#1170").

But there is no need to send a new version just for this -- the
maintainers may want to fix it on apply, so please wait to see what
they say.

Thanks!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rust : Update the bios_limit_callback to use the C FFI types #1170
  2025-06-12 10:41 [PATCH v2] rust : Update the bios_limit_callback to use the C FFI types #1170 Abhinav Ananthu
  2025-06-12 11:55 ` Miguel Ojeda
@ 2025-06-13  3:08 ` Viresh Kumar
  1 sibling, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2025-06-13  3:08 UTC (permalink / raw)
  To: Abhinav Ananthu
  Cc: Rafael J . Wysocki, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, linux-pm,
	rust-for-linux, linux-kernel

Hi Abhinav,

Thanks for looking into this..

On 12-06-25, 16:11, Abhinav Ananthu wrote:
> diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
> index b0a9c6182aec..e97607ed86c2 100644
> --- a/rust/kernel/cpufreq.rs
> +++ b/rust/kernel/cpufreq.rs
> @@ -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)?;

There are a couple of more FFI callbacks which use `u32`, `usize`,
etc.. Can you please fix them all, basically all callbacks with `unsafe
extern "C"`.

Also please rebase over linux-next/master, there are few recent
updates available there.

-- 
viresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-13  3:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-12 10:41 [PATCH v2] rust : Update the bios_limit_callback to use the C FFI types #1170 Abhinav Ananthu
2025-06-12 11:55 ` Miguel Ojeda
2025-06-13  3:08 ` Viresh Kumar
  -- strict thread matches above, loose matches on Subject: below --
2025-06-12 10:42 Abhinav Ananthu
2025-06-12 11:51 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).