]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
rust: types: avoid repetition in `{As,From}Bytes` impls
authorMiguel Ojeda <ojeda@kernel.org>
Fri, 7 Mar 2025 22:49:10 +0000 (23:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 12:01:40 +0000 (13:01 +0100)
commit870de86d874e6d2596f5309df545b8eab8aef6a3
treebec33299e13ec317680bb339f67af7b14d709215
parent3166e8aed0e05eefddcf1eeea0f6f63488a376d1
rust: types: avoid repetition in `{As,From}Bytes` impls

commit 567cdff53e71de56ae67eaf4309db38778b7bcd3 upstream.

In order to provide `// SAFETY` comments for every `unsafe impl`, we would
need to repeat them, which is not very useful and would be harder to read.

We could perhaps allow the lint (ideally within a small module), but we
can take the chance to avoid the repetition of the `impl`s themselves
too by using a small local macro, like in other places where we have
had to do this sort of thing.

Thus add the straightforward `impl_{from,as}bytes!` macros and use them
to implement `FromBytes`.

This, in turn, will allow us in the next patch to place a `// SAFETY`
comment that defers to the actual invocation of the macro.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Tested-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20240904204347.168520-4-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
rust/kernel/types.rs