Re: [PATCH v8 1/1] rust: introduce abstractions for fwctl
"Alexandre Courbot" <[email protected]>
| Newsgroups | org.kernel.vger.rust-for-linux,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On Sat Aug 15, 2026 at 8:25 AM JST, Gary Guo wrote:
> On Thu Aug 13, 2026 at 4:23 PM BST, Zhi Wang wrote:
>> diff --git a/rust/kernel/fwctl.rs b/rust/kernel/fwctl.rs
>> new file mode 100644
>> index 000000000000..e6a8513a47d0
>> --- /dev/null
>> +++ b/rust/kernel/fwctl.rs
>> @@ -0,0 +1,593 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +
>> +//! Abstractions for the fwctl subsystem.
>> +//!
>> +//! C header: `include/linux/fwctl.h`
>> +
>> +use crate::{
>> + bindings,
>> + container_of,
>> + device,
>> + prelude::*,
>> + sync::aref::{
>> + ARef,
>> + AlwaysRefCounted, //
>> + },
>> + types::Opaque, //
>> +};
>> +use core::{
>> + alloc::Layout,
>> + cell::UnsafeCell,
>> + marker::PhantomData,
>> + ptr::NonNull,
>> + slice, //
>> +};
>> +
>> +/// Returns a kmalloc-compatible allocation size for `T`.
>> +const fn kmalloc_aligned_size<T>() -> usize {
>> + Layout::new::<T>().pad_to_align().size()
>
> What's this function doing? This is just identical to `size_of::<T>()`.
>
> The layout from a specific type is already padded to its alignment. You only
> need to call `pad_to_align()`, say, if you are computing a layout or increasing
> the alignment of layout.
IIRC this was meant to be a const version of `Kmalloc::aligned_layout`
[1], which although it is equivalent carries the intent better than just
using `size_of`. But here it would maybe be better to just make
`Kmalloc::aligned_layout` const and call it instead.
[1] https://lore.kernel.org/all/[email protected]/