Re: [PATCH] configfs: rust: add an API for adding default groups from C
From: Danilo Krummrich
Date: Mon Feb 16 2026 - 04:58:45 EST
On Sun Feb 15, 2026 at 9:33 PM CET, Andreas Hindborg wrote:
> @@ -259,7 +269,13 @@ pub fn new(
> name: CString,
> item_type: &'static ItemType<Group<Data>, Data>,
> data: impl PinInit<Data, Error>,
> + default_groups: impl IntoIterator<Item = Arc<dyn CDefaultGroup>>,
> ) -> impl PinInit<Self, Error> {
> + let mut dg = KVec::new();
> + for group in default_groups {
> + dg.push(group, GFP_KERNEL).unwrap();
We should not panic the kernel on allocation failure.
If you wrap the function body into pin_init::pin_init_scope() you can just use
the '?' operator instead.
> + }
> +
> try_pin_init!(Self {
> group <- pin_init::init_zeroed().chain(|v: &mut Opaque<bindings::config_group>| {
> let place = v.get();
> @@ -268,13 +284,28 @@ pub fn new(
> unsafe {
> bindings::config_group_init_type_name(place, name.cast(), item_type.as_ptr())
> };
> +
> + for default_group in &dg {
> + // SAFETY: We keep the default groups alive until `Self` is dropped.
> + unsafe { bindings::configfs_add_default_group(default_group.group_ptr(), place) }
> + }
> Ok(())
> }),
> data <- data,
> + default_groups: dg,
> })
> }
> }