dc35ddcf | 15-Jun-2025 |
Tamir Duberstein <tamird@gmail.com> |
rust: enable `clippy::ref_as_ptr` lint
In Rust 1.78.0, Clippy introduced the `ref_as_ptr` lint [1]:
> Using `as` casts may result in silently changing mutability or type.
While this doesn't elimin
rust: enable `clippy::ref_as_ptr` lint
In Rust 1.78.0, Clippy introduced the `ref_as_ptr` lint [1]:
> Using `as` casts may result in silently changing mutability or type.
While this doesn't eliminate unchecked `as` conversions, it makes such conversions easier to scrutinize. It also has the slight benefit of removing a degree of freedom on which to bikeshed. Thus apply the changes and enable the lint -- no functional change intended.
Link: https://rust-lang.github.io/rust-clippy/master/index.html#ref_as_ptr [1] Suggested-by: Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/all/D8PGG7NTWB6U.3SS3A5LN4XWMN@proton.me/ Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Tamir Duberstein <tamird@gmail.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20250615-ptr-as-ptr-v12-6-f43b024581e8@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
b7c8d7a8 | 15-Jun-2025 |
Tamir Duberstein <tamird@gmail.com> |
rust: enable `clippy::cast_lossless` lint
Before Rust 1.29.0, Clippy introduced the `cast_lossless` lint [1]:
> Rust’s `as` keyword will perform many kinds of conversions, including > silently loss
rust: enable `clippy::cast_lossless` lint
Before Rust 1.29.0, Clippy introduced the `cast_lossless` lint [1]:
> Rust’s `as` keyword will perform many kinds of conversions, including > silently lossy conversions. Conversion functions such as `i32::from` > will only perform lossless conversions. Using the conversion functions > prevents conversions from becoming silently lossy if the input types > ever change, and makes it clear for people reading the code that the > conversion is lossless.
While this doesn't eliminate unchecked `as` conversions, it makes such conversions easier to scrutinize. It also has the slight benefit of removing a degree of freedom on which to bikeshed. Thus apply the changes and enable the lint -- no functional change intended.
Link: https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless [1] Suggested-by: Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/all/D8ORTXSUTKGL.1KOJAGBM8F8TN@proton.me/ Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Tamir Duberstein <tamird@gmail.com> Acked-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Acked-by: Jocelyn Falempe <jfalempe@redhat.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20250615-ptr-as-ptr-v12-5-f43b024581e8@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
8cbc95f9 | 25-Mar-2025 |
Miguel Ojeda <ojeda@kernel.org> |
rust: workaround `bindgen` issue with forward references to `enum` types
`bindgen` currently generates the wrong type for an `enum` when there is a forward reference to it. For instance:
enum E
rust: workaround `bindgen` issue with forward references to `enum` types
`bindgen` currently generates the wrong type for an `enum` when there is a forward reference to it. For instance:
enum E; enum E { A };
generates:
pub const E_A: E = 0; pub type E = i32;
instead of the expected:
pub const E_A: E = 0; pub type E = ffi::c_uint;
The issue was reported to upstream `bindgen` [1].
Now, both GCC and Clang support silently these forward references to `enum` types, unless `-Wpedantic` is passed, and it turns out that some headers in the kernel depend on them.
Thus, depending on how the headers are included, which in turn may depend on the kernel configuration or the architecture, we may get a different type on the Rust side for a given C `enum`.
That can be quite confusing, to say the least, especially since developers may only notice issues when building for other architectures like in [2]. In particular, they may end up forcing a cast and adding an `#[allow(clippy::unnecessary_cast)]` like it was done in commit 94e05a66ea3e ("rust: hrtimer: allow timer restart from timer handler"), which isn't great.
Instead, let's have a section at the top of our `bindings_helper.h` that `#include`s the headers with the affected types -- hopefully there are not many cases and there is a single ordering that covers all cases.
This allows us to remove the cast and the `#[allow]`, thus keeping the correct code in the source files. When the issue gets resolved in upstream `bindgen` (and we update our minimum `bindgen` version), we can easily remove this section at the top.
Link: https://github.com/rust-lang/rust-bindgen/issues/3179 [1] Link: https://lore.kernel.org/rust-for-linux/87tt7md1s6.fsf@kernel.org/ [2] Acked-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://lore.kernel.org/r/20250325184309.97170-1-ojeda@kernel.org [ Added extra paragraph on the comment to clarify that the workaround may not be possible in some cases. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
2207856f | 07-Jan-2025 |
Viresh Kumar <viresh.kumar@linaro.org> |
rust: cpufreq: Add initial abstractions for cpufreq framework
Introduce initial Rust abstractions for the cpufreq core. This includes basic representations for cpufreq flags, relation types, and the
rust: cpufreq: Add initial abstractions for cpufreq framework
Introduce initial Rust abstractions for the cpufreq core. This includes basic representations for cpufreq flags, relation types, and the cpufreq table.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
show more ...
|
8f835497 | 18-Dec-2023 |
Viresh Kumar <viresh.kumar@linaro.org> |
rust: opp: Add initial abstractions for OPP framework
Introduce initial Rust abstractions for the Operating Performance Points (OPP) framework. This includes bindings for `struct dev_pm_opp` and `st
rust: opp: Add initial abstractions for OPP framework
Introduce initial Rust abstractions for the Operating Performance Points (OPP) framework. This includes bindings for `struct dev_pm_opp` and `struct dev_pm_opp_data`, laying the groundwork for further OPP integration.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
show more ...
|
3accb57d | 08-Jan-2025 |
Viresh Kumar <viresh.kumar@linaro.org> |
rust: cpu: Add from_cpu()
This implements cpu::from_cpu(), which returns a reference to Device for a CPU. The C struct is created at initialization time for CPUs and is never freed and so ARef isn't
rust: cpu: Add from_cpu()
This implements cpu::from_cpu(), which returns a reference to Device for a CPU. The C struct is created at initialization time for CPUs and is never freed and so ARef isn't returned from this function.
The new helper will be used by Rust based cpufreq drivers.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
show more ...
|
c284d3e4 | 11-Apr-2025 |
Asahi Lina <lina@asahilina.net> |
rust: drm: gem: Add GEM object abstraction
DRM GEM is the DRM memory management subsystem used by most modern drivers; add a Rust abstraction for DRM GEM.
This includes the BaseObject trait, which
rust: drm: gem: Add GEM object abstraction
DRM GEM is the DRM memory management subsystem used by most modern drivers; add a Rust abstraction for DRM GEM.
This includes the BaseObject trait, which contains operations shared by all GEM object classes.
Signed-off-by: Asahi Lina <lina@asahilina.net> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Lyude Paul <lyude@redhat.com> Link: https://lore.kernel.org/r/20250410235546.43736-8-dakr@kernel.org [ Rework of GEM object abstractions * switch to the Opaque<T> type * fix (mutable) references to struct drm_gem_object (which in this context is UB) * drop all custom reference types in favor of AlwaysRefCounted * bunch of minor changes and simplifications (e.g. IntoGEMObject trait) * write and fix safety and invariant comments * remove necessity for and convert 'as' casts * original source archive: https://archive.is/dD5SL
- Danilo ] [ Fix missing CONFIG_DRM guards in rust/helpers/drm.c. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
a98a73be | 11-Apr-2025 |
Asahi Lina <lina@asahilina.net> |
rust: drm: file: Add File abstraction
A DRM File is the DRM counterpart to a kernel file structure, representing an open DRM file descriptor.
Add a Rust abstraction to allow drivers to implement th
rust: drm: file: Add File abstraction
A DRM File is the DRM counterpart to a kernel file structure, representing an open DRM file descriptor.
Add a Rust abstraction to allow drivers to implement their own File types that implement the DriverFile trait.
Reviewed-by: Maxime Ripard <mripard@kernel.org> Signed-off-by: Asahi Lina <lina@asahilina.net> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Lyude Paul <lyude@redhat.com> Link: https://lore.kernel.org/r/20250410235546.43736-7-dakr@kernel.org [ Rework of drm::File * switch to the Opaque<T> type * fix (mutable) references to struct drm_file (which in this context is UB) * restructure and rename functions to align with common kernel schemes * write and fix safety and invariant comments * remove necessity for and convert 'as' casts * original source archive: https://archive.is/GH8oy
- Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
1e4b8896 | 11-Apr-2025 |
Asahi Lina <lina@asahilina.net> |
rust: drm: add device abstraction
Implement the abstraction for a `struct drm_device`.
A `drm::Device` creates a static const `struct drm_driver` filled with the data from the `drm::Driver` trait i
rust: drm: add device abstraction
Implement the abstraction for a `struct drm_device`.
A `drm::Device` creates a static const `struct drm_driver` filled with the data from the `drm::Driver` trait implementation of the actual driver creating the `drm::Device`.
Reviewed-by: Maxime Ripard <mripard@kernel.org> Signed-off-by: Asahi Lina <lina@asahilina.net> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Lyude Paul <lyude@redhat.com> Link: https://lore.kernel.org/r/20250410235546.43736-5-dakr@kernel.org [ Rewrite of drm::Device * full rewrite of the drm::Device abstraction using the subclassing pattern * original source archive: http://archive.today/5NxBo
- Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|