[PATCH 0/2] rust: debugfs: migrate BinaryWriter requirements to zerocopy

Josef Ippisch via B4 Relay posted 2 patches 5 days, 18 hours ago
rust/kernel/debugfs/traits.rs | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
[PATCH 0/2] rust: debugfs: migrate BinaryWriter requirements to zerocopy
Posted by Josef Ippisch via B4 Relay 5 days, 18 hours ago
Migrates the `BinaryWriter` default implementation requirements from
`kernel::transmute::IntoBytes` to `zerocopy::Immutable` +
`zerocopy::IntoBytes`.

This is part of a bigger migration from rust/kernel/transmute.rs to the
zerocopy crate, see also [1] and [2]

[1] https://github.com/Rust-for-Linux/linux/issues/975
[2] https://github.com/Rust-for-Linux/linux/issues/1241

The crate zerocopy was introduced with

c37398010a05 rust: zerocopy: import crate

This introduced among other things the `IntoBytes` trait that, when
derived, does better checks on the actual requirements of the types than
the existing `kernel::transmute::AsBytes`.

This is my first kernel patch so please let me know if I do anything wrong
process wise or regarding some other aspect!

There are some other points that I came across when investigating this

- rust/kernel/debugfs/traits.rs still depends on
  `kernel::transmute::AsBytes` for `BinaryReaderMut`.  Should I directly
  migrate this also in this patch series? This would require migrating also
  to `zerocopy::FromBytes` as the implemention for T depends on both
  `AsBytes + FromBytes` currently.
- I noticed that we could probably get rid of the `BinaryWriter`
  implementation for `Vec` altogether if we implemented `Immutable` and
  `IntoBytes` for `Vec`.  These are already implemented for [T] after
  all. What do you think?

Suggested-by: Joshua Liebow-Feeser <joshlf@google.com>
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://github.com/Rust-for-Linux/linux/issues/975
Signed-off-by: Josef Ippisch <josef.ippisch.dev@mailbox.org>
---
Josef Ippisch (2):
      rust: debugfs: migrate BinaryWriter requirements to zerocopy
      rust: debugfs: remove unsafe block from BinaryWriter impl for Vec

 rust/kernel/debugfs/traits.rs | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
---
base-commit: 7059bdf4f04a3e14f4fafb3ac35fdca913e3e21a
change-id: 20260719-migrate-binarywriter-to-zerocopy-intobytes-1e8f4ef93a60

Best regards,
--  
Josef Ippisch <josef.ippisch.dev@mailbox.org>