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

Josef Ippisch via B4 Relay <[email protected]>
Newsgroups dev.linux.lists.driver-core,org.kernel.feeds.b4-sent,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux
Message-ID <20260719-migrate-binarywriter-to-zerocopy-intobytes-v1-0-27ed30512e75@mailbox.org>
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 <[email protected]>
Suggested-by: Miguel Ojeda <[email protected]>
Link: https://github.com/Rust-for-Linux/linux/issues/975
Signed-off-by: Josef Ippisch <[email protected]>
---
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 <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.