From nobody Mon May 25 00:08:04 2026 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 880CF37CD46 for ; Wed, 20 May 2026 07:40:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779262856; cv=none; b=Twi9VvLlTU6Fqxy0t2rtYzgQFhPZ1eH6j7XzieiJR/4U+LlXJLw48mld7A6mole13rWNLVaLBl2DTtL01nUj9dP0xX4InTZdINpwoTDZ+Ty1cid/COaShbFqguEyN6xNVWy+8mvFXsia/HRUD99y6rxBJS8llz9/CS1K3NnKk+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779262856; c=relaxed/simple; bh=eqMsKmMrVPR5kTGUkImNiDqvCNPz4fpwi1svfEwYHCs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=fsMBtav0G9urk1edgJxbN4wjJeEzue/VO1+JFK+CTLEPkktU9AZjrzwxfEpdLwORUF0+W8Ow8s2deRgXSGpPTsKHzAlwgpQuwIAyUxEp5JI4E0M3WWXGl3VILF2vUy152ZX/YCkdd6TTVCzGg64n/R3VnvY3SgNoUuBH7ua/CD4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mQYOLMUj; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mQYOLMUj" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-488ff90d6c7so34492275e9.2 for ; Wed, 20 May 2026 00:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779262853; x=1779867653; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=RO+tCCCSue2id/N4emUlo+MAydiQkdwgenz3gSYRrYw=; b=mQYOLMUjQWJQsgd+bzspwyHzGraF5uX3F7uI8pwVpph5VAZM2tIbHtVMfMPG1GQrqD igapuP3072IiJnWpcHUaSZGHlrqHIvBTKsLS3CV6x2NVsIIR8AFoDvDgEUseXmkEtG7E HLAcAHuXQmexzecHWXps+fsfkCZHh14r/pglsmBB2oM52yIgtRYlD2Oi8x9HpgTlP/tG eF/RHuSfwNCWpz2jfjzTZerlkpNnrBslld244EyFK6l6KpOMowVrRmUxHS1UmLPwesYo N3MfyllEGRzd2Pk4kfL5ov5ZfEwBRZZ6KPy7gxO42CilQvDWOZIzPq213jnidDejwnLu Ohjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779262853; x=1779867653; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RO+tCCCSue2id/N4emUlo+MAydiQkdwgenz3gSYRrYw=; b=UUkdcqVnOBI1brRshAK7+FtDj68HVomKqgSQ3pHfmxHV/v+xrHhVK6RkTc+Nc6ECuB gyu4YEaHcfsCVgvS/K/E6f3HE+B8QQUTJ+vDy5GbJobzE/ZIhuA/nl+wtn0MkjCSMumT RoVnvE5ut6wthEpQgcAetYJyPLT2bqQtQNcMWjz6AYR0ZHl13x8uYmt3X0dFKebKEa1K U50lBiVIbejlecAKSIIR5YBu87fj7RcMLZVmv1Y86Q2nMCPmWo9uzhDG6tKMXLH8t1A3 SoOFjRkxenUht148IKA76G/NnlihythR3v+5Cs92hEUTvqrywdxJzbPdPm1AoFq/rMne U3OQ== X-Gm-Message-State: AOJu0YwMU2ze1TNC2tfV6Y/bUXnhyHVIRGTvAgw2QA1cGJga8x6u6tap TgOV5LWdGyGExAcGWXRsRpkzIy/DSP6nf05x/AjaCS7R1ZMbaeX2cV6FCOv701XZBLc= X-Gm-Gg: Acq92OHkGkPpWeeldXTTO729gANKFTi3YpFfAc3o/2l7xWQXTyqZbqNGPEu8JA0GxFy /GTeSsM8sTU0EaaJjOZ3sX9+Y+DJ7zOfFbYhVPzAsN0yiAYV0vK5W1LKMg4rYcu3wBNZK/HU8Rf meMPi63nsalWP/sN2QlzQUbQLi7qHCI6K5pu7rZF1GJZXRrqvxyrSxsTQa7HlYSwGWG8WqL2FCd cLO9MHVYLhXpas5WSEFHk9niGgD1mxE/wf1IcRzxmQZ1un9O2Q/IjxGjhBG5NqAwF3U2FFX96HN BEap9r8hGBmpe686kimTzj2mypwpb10W93HEPUp58cCx5mI7MTtQ/2dljT1fru5C1Y+9XKoQleV XNu3E+UvgJiVVydgrnRIoRGpvXIo4M32Y0GxZwIjggZdRC8utIv123GCNkuOMeUZRaTDajoCYub gTpy7mEDXoZDK9POVGk/Lvlr4Xtq2L8KE= X-Received: by 2002:a05:600c:3f0f:b0:48f:99a9:bbcc with SMTP id 5b1f17b1804b1-48fe60ecb9cmr331867205e9.10.1779262852614; Wed, 20 May 2026 00:40:52 -0700 (PDT) Received: from [172.16.16.15] ([195.100.225.50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45da0a17ec2sm48745498f8f.24.2026.05.20.00.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 00:40:51 -0700 (PDT) From: Malte Wechter Date: Wed, 20 May 2026 09:40:43 +0200 Subject: [PATCH] rust: add procedural macro for declaring configfs attributes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260520-configfs-syn-v1-1-6c5b80a9cef2@gmail.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/x3MMQqAMAxA0atIZgtJFYteRRxE05qllQZEKd7d4 viG/wsoZ2GFqSmQ+RKVFCuobWA71hjYyF4NFu2APTmzpegleDX6REMjMTrqEK2DmpyZvdz/bl7 e9wOxG6tRXgAAAA== X-Change-ID: 20260417-configfs-syn-191e07130027 To: Andreas Hindborg , Breno Leitao , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-block@vger.kernel.org, Malte Wechter X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779262850; l=20458; i=maltewechter@gmail.com; s=20260417; h=from:subject:message-id; bh=eqMsKmMrVPR5kTGUkImNiDqvCNPz4fpwi1svfEwYHCs=; b=amZHOz9q1YH339fxUURIj3C4BOXBz/q1/NQ/nA0ZfHzZwuGT8bybEr0H/VH+yzy2a+9nQGVs8 2ncX54J0epuAb7k6rvVeqJpWV3/fDMAbuB/7wa5H4yAFS0oRSDB9CpJ X-Developer-Key: i=maltewechter@gmail.com; a=ed25519; pk=07WplWXZnwyLTMZOHNCIGcpoEutcMXU/JDY6f9VtxSY= Implement `configfs_attrs!` as a procedural macro using `syn`, this improves readability and maintainability. Remove the old macro and replace all uses with the new macro. Add the new macro implementation file to MAINTAINERS. Signed-off-by: Malte Wechter --- MAINTAINERS | 1 + drivers/block/rnull/configfs.rs | 2 +- rust/kernel/configfs.rs | 251 ------------------------------------= ---- rust/macros/configfs_attrs.rs | 182 +++++++++++++++++++++++++++++ rust/macros/lib.rs | 85 ++++++++++++++ samples/rust/rust_configfs.rs | 2 +- 6 files changed, 270 insertions(+), 253 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 2fb1c75afd163..45f7a1ec93b45 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6464,6 +6464,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/= a.hindborg/linux.git config F: fs/configfs/ F: include/linux/configfs.h F: rust/kernel/configfs.rs +F: rust/macros/configfs_attrs.rs F: samples/configfs/ F: samples/rust/rust_configfs.rs =20 diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs= .rs index 7c2eb5c0b7228..f28ec69d79846 100644 --- a/drivers/block/rnull/configfs.rs +++ b/drivers/block/rnull/configfs.rs @@ -4,8 +4,8 @@ use kernel::{ block::mq::gen_disk::{GenDisk, GenDiskBuilder}, configfs::{self, AttributeOperations}, - configfs_attrs, fmt::{self, Write as _}, + macros::configfs_attrs, new_mutex, page::PAGE_SIZE, prelude::*, diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs index 2339c6467325d..7a91e36677f52 100644 --- a/rust/kernel/configfs.rs +++ b/rust/kernel/configfs.rs @@ -791,254 +791,3 @@ fn as_ptr(&self) -> *const bindings::config_item_type= { self.item_type.get() } } - -/// Define a list of configfs attributes statically. -/// -/// Invoking the macro in the following manner: -/// -/// ```ignore -/// let item_type =3D configfs_attrs! { -/// container: configfs::Subsystem, -/// data: Configuration, -/// child: Child, -/// attributes: [ -/// message: 0, -/// bar: 1, -/// ], -/// }; -/// ``` -/// -/// Expands the following output: -/// -/// ```ignore -/// let item_type =3D { -/// static CONFIGURATION_MESSAGE_ATTR: kernel::configfs::Attribute< -/// 0, -/// Configuration, -/// Configuration, -/// > =3D unsafe { -/// kernel::configfs::Attribute::new({ -/// const S: &str =3D "message\u{0}"; -/// const C: &kernel::str::CStr =3D match kernel::str::CStr::f= rom_bytes_with_nul( -/// S.as_bytes() -/// ) { -/// Ok(v) =3D> v, -/// Err(_) =3D> { -/// core::panicking::panic_fmt(core::const_format_args= !( -/// "string contains interior NUL" -/// )); -/// } -/// }; -/// C -/// }) -/// }; -/// -/// static CONFIGURATION_BAR_ATTR: kernel::configfs::Attribute< -/// 1, -/// Configuration, -/// Configuration -/// > =3D unsafe { -/// kernel::configfs::Attribute::new({ -/// const S: &str =3D "bar\u{0}"; -/// const C: &kernel::str::CStr =3D match kernel::str::CStr::f= rom_bytes_with_nul( -/// S.as_bytes() -/// ) { -/// Ok(v) =3D> v, -/// Err(_) =3D> { -/// core::panicking::panic_fmt(core::const_format_args= !( -/// "string contains interior NUL" -/// )); -/// } -/// }; -/// C -/// }) -/// }; -/// -/// const N: usize =3D (1usize + (1usize + 0usize)) + 1usize; -/// -/// static CONFIGURATION_ATTRS: kernel::configfs::AttributeList =3D -/// unsafe { kernel::configfs::AttributeList::new() }; -/// -/// { -/// const N: usize =3D 0usize; -/// unsafe { CONFIGURATION_ATTRS.add::(&CONFIGURATION_MES= SAGE_ATTR) }; -/// } -/// -/// { -/// const N: usize =3D (1usize + 0usize); -/// unsafe { CONFIGURATION_ATTRS.add::(&CONFIGURATION_BAR= _ATTR) }; -/// } -/// -/// static CONFIGURATION_TPE: -/// kernel::configfs::ItemType ,C= onfiguration> -/// =3D kernel::configfs::ItemType::< -/// configfs::Subsystem, -/// Configuration -/// >::new_with_child_ctor::( -/// &THIS_MODULE, -/// &CONFIGURATION_ATTRS -/// ); -/// -/// &CONFIGURATION_TPE -/// } -/// ``` -#[macro_export] -macro_rules! configfs_attrs { - ( - container: $container:ty, - data: $data:ty, - attributes: [ - $($name:ident: $attr:literal),* $(,)? - ] $(,)? - ) =3D> { - $crate::configfs_attrs!( - count: - @container($container), - @data($data), - @child(), - @no_child(x), - @attrs($($name $attr)*), - @eat($($name $attr,)*), - @assign(), - @cnt(0usize), - ) - }; - ( - container: $container:ty, - data: $data:ty, - child: $child:ty, - attributes: [ - $($name:ident: $attr:literal),* $(,)? - ] $(,)? - ) =3D> { - $crate::configfs_attrs!( - count: - @container($container), - @data($data), - @child($child), - @no_child(), - @attrs($($name $attr)*), - @eat($($name $attr,)*), - @assign(), - @cnt(0usize), - ) - }; - (count: - @container($container:ty), - @data($data:ty), - @child($($child:ty)?), - @no_child($($no_child:ident)?), - @attrs($($aname:ident $aattr:literal)*), - @eat($name:ident $attr:literal, $($rname:ident $rattr:literal,)*), - @assign($($assign:block)*), - @cnt($cnt:expr), - ) =3D> { - $crate::configfs_attrs!( - count: - @container($container), - @data($data), - @child($($child)?), - @no_child($($no_child)?), - @attrs($($aname $aattr)*), - @eat($($rname $rattr,)*), - @assign($($assign)* { - const N: usize =3D $cnt; - // The following macro text expands to a call to `Attribut= e::add`. - - // SAFETY: By design of this macro, the name of the variab= le we - // invoke the `add` method on below, is not visible outsid= e of - // the macro expansion. The macro does not operate concurr= ently - // on this variable, and thus we have exclusive access to = the - // variable. - unsafe { - $crate::macros::paste!( - [< $data:upper _ATTRS >] - .add::(&[< $data:upper _ $name:up= per _ATTR >]) - ) - }; - }), - @cnt(1usize + $cnt), - ) - }; - (count: - @container($container:ty), - @data($data:ty), - @child($($child:ty)?), - @no_child($($no_child:ident)?), - @attrs($($aname:ident $aattr:literal)*), - @eat(), - @assign($($assign:block)*), - @cnt($cnt:expr), - ) =3D> - { - $crate::configfs_attrs!( - final: - @container($container), - @data($data), - @child($($child)?), - @no_child($($no_child)?), - @attrs($($aname $aattr)*), - @assign($($assign)*), - @cnt($cnt), - ) - }; - (final: - @container($container:ty), - @data($data:ty), - @child($($child:ty)?), - @no_child($($no_child:ident)?), - @attrs($($name:ident $attr:literal)*), - @assign($($assign:block)*), - @cnt($cnt:expr), - ) =3D> - { - $crate::macros::paste!{ - { - $( - // SAFETY: We are expanding `configfs_attrs`. - static [< $data:upper _ $name:upper _ATTR >]: - $crate::configfs::Attribute<$attr, $data, $data> = =3D - unsafe { - $crate::configfs::Attribute::new( - $crate::c_str!(::core::stringify!($nam= e)), - ) - }; - )* - - - // We need space for a null terminator. - const N: usize =3D $cnt + 1usize; - - // SAFETY: We are expanding `configfs_attrs`. - static [< $data:upper _ATTRS >]: - $crate::configfs::AttributeList =3D - unsafe { $crate::configfs::AttributeList::new() }; - - $($assign)* - - $( - const [<$no_child:upper>]: bool =3D true; - - static [< $data:upper _TPE >] : $crate::configfs::Item= Type<$container, $data> =3D - $crate::configfs::ItemType::<$container, $data>::n= ew::( - &THIS_MODULE, &[<$ data:upper _ATTRS >] - ); - )? - - $( - static [< $data:upper _TPE >]: - $crate::configfs::ItemType<$container, $data> =3D - $crate::configfs::ItemType::<$container, $data= >:: - new_with_child_ctor::( - &THIS_MODULE, &[<$ data:upper _ATTRS >] - ); - )? - - & [< $data:upper _TPE >] - } - } - }; - -} - -pub use crate::configfs_attrs; diff --git a/rust/macros/configfs_attrs.rs b/rust/macros/configfs_attrs.rs new file mode 100644 index 0000000000000..f5c3a8d9bffbd --- /dev/null +++ b/rust/macros/configfs_attrs.rs @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0 + +use quote::{ + quote, // + ToTokens, +}; + +use proc_macro2::{ + Span, // +}; + +use syn::{ + bracketed, + parse::{ + Parse, + ParseStream, // + }, + punctuated::Punctuated, + spanned::Spanned, + Ident, + LitInt, + Token, + Type, // +}; + +pub(crate) struct ConfigfsAttrs { + container: Type, + data: Type, + child: Option, + attributes: Vec<(Ident, LitInt)>, +} + +fn parse_attribute_field(stream: ParseStream<'_>) -> syn::Result<(Ident, L= itInt)> { + let id =3D stream.parse::()?; + let _colon =3D stream.parse::()?; + let v =3D stream.parse::()?; + Ok((id, v)) +} + +fn parse_named_field(stream: ParseStream<'_>, name: &str) -> syn::Result { + let try_stream =3D stream.fork(); + let name_id =3D try_stream.parse::()?; + if name_id !=3D name { + return Err(parse_field_error(name_id.span(), &name_id, name)); + } + let _name_id =3D stream.parse::()?; + let _colon =3D stream.parse::()?; + let v =3D stream.parse::()?; + stream.parse::()?; + Ok(v) +} + +fn parse_attributes(stream: ParseStream<'_>) -> syn::Result> { + let attribute_id =3D stream.parse::()?; + if attribute_id !=3D "attributes" { + return Err(syn::Error::new( + attribute_id.span(), + format!( + "unexpected identifier: {}, expected: 'attributes'", + attribute_id + ), + )); + } + stream.parse::()?; + let attr_stream; + let _bracket =3D bracketed!(attr_stream in stream); + let attributes =3D Punctuated::<(Ident, LitInt), Token![,]>::parse_ter= minated_with( + &attr_stream, + parse_attribute_field, + )?; + let attributes =3D attributes.into_iter().collect::>(); + + stream.parse::>()?; + Ok(attributes) +} + +fn parse_field_error(span: Span, name: &Ident, expected_name: &str) -> syn= ::Error { + syn::Error::new( + span, + format!("Unexpected field name, got: {name} expected: {expected_na= me}"), + ) +} + +impl Parse for ConfigfsAttrs { + fn parse(input: ParseStream<'_>) -> syn::Result { + let container =3D parse_named_field(input, "container")?; + let data =3D parse_named_field(input, "data")?; + let child =3D parse_named_field(input, "child").ok(); + let attributes =3D parse_attributes(input)?; + + Ok(ConfigfsAttrs { + container, + data, + child, + attributes, + }) + } +} + +fn make_static_ident(ty: &T, suffix: &str) -> syn::Ident { + let raw_id =3D quote! { #ty }.to_string(); + + // Sanitizing syn::Type::Path, this is safe since it is + // only used as the identifier. + let normalized =3D raw_id + .split("::") + .map(|s| String::from(s.trim())) + .reduce(|a, b| format!("{a}_{b}")) + .expect("Cannot be empty") + .to_uppercase() + .replace(|c: char| !c.is_alphanumeric(), "_"); + + Ident::new(&format!("{}_{}", normalized, suffix), ty.span()) +} + +pub(crate) fn configfs_attrs(cfs_attrs: ConfigfsAttrs) -> proc_macro2::Tok= enStream { + let (container_ty, data_ty) =3D (&cfs_attrs.container, &cfs_attrs.data= ); + + let data_tp_ident =3D make_static_ident(data_ty, "TPE"); + let data_attr_ident =3D make_static_ident(data_ty, "ATTR_LIST"); + + let n =3D cfs_attrs.attributes.len() + 1; + + let attr_list =3D quote! { + static #data_attr_ident: kernel::configfs::AttributeList<#n, #data= _ty> =3D + // SAFETY: We are expanding `configfs_attrs`. + unsafe { kernel::configfs::AttributeList::new() }; + }; + + let mut attrs =3D Vec::new(); + for (attr_idx, (name, id)) in cfs_attrs.attributes.iter().enumerate() { + let name_with_attr =3D make_static_ident(name, "ATTR"); + + let id: u64 =3D match id.base10_parse::() { + Ok(v) =3D> v, + Err(_) =3D> { + return syn::Error::new(id.span(), "Could not parse attribu= te ID as a u64") + .to_compile_error(); + } + }; + + attrs.push(quote! { + static #name_with_attr: kernel::configfs::Attribute<#id, #data_ty,= #data_ty> =3D + // SAFETY: We are expanding `configfs_attrs`. + unsafe { + kernel::configfs::Attribute::new(kernel::c_str!(::core::stri= ngify!(#name))) + }; + + // SAFETY: By design of this macro, the name of the variable we + // invoke the `add` method on below, is not visible outside of + // the macro expansion. The macro does not operate concurrently + // on this variable, and thus we have exclusive access to the + // variable. + unsafe { #data_attr_ident.add::<#attr_idx, #id, _>(&#name_with_a= ttr) } + }); + } + + let has_child_code =3D if let Some(child) =3D cfs_attrs.child { + quote! { new_with_child_ctor::<#n, #child>} + } else { + quote! { new::<#n> } + }; + + let data_type =3D quote! { + { + static #data_tp_ident: + kernel::configfs::ItemType<#container_ty, #data_ty> =3D + kernel::configfs::ItemType::<#container_ty, #data_ty>::#ha= s_child_code( + &THIS_MODULE, &#data_attr_ident + ); + &#data_tp_ident + } + }; + + quote! { + { + #attr_list + #(#attrs)* + #data_type + } + } +} diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs index 2cfd59e0f9e7c..745ba83c828b9 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -15,6 +15,8 @@ #![cfg_attr(not(CONFIG_RUSTC_HAS_SPAN_FILE), feature(proc_macro_span))] =20 mod concat_idents; +#[cfg(CONFIG_CONFIGFS_FS)] +mod configfs_attrs; mod export; mod fmt; mod helpers; @@ -489,3 +491,86 @@ pub fn kunit_tests(attr: TokenStream, input: TokenStre= am) -> TokenStream { .unwrap_or_else(|e| e.into_compile_error()) .into() } + +/// Define a list of configfs attributes statically. +/// +/// # Examples +/// +/// ```ignore +/// let item_type =3D configfs_attrs! { +/// container: configfs::Subsystem, +/// data: Configuration, +/// child: Child, +/// attributes: [ +/// message: 0, +/// bar: 1, +/// ], +/// }; +///``` +/// +/// Expands the following output: +/// let item_type =3D { +/// static CONFIGURATION_ATTR_LIST: kernel::configfs::AttributeLis= t< +/// 3usize, +/// Configuration, +/// > =3D unsafe { kernel::configfs::AttributeList::new() }; +/// static MESSAGE_ATTR: kernel::configfs::Attribute< +/// 0u64, +/// Configuration, +/// Configuration, +/// > =3D unsafe { +/// kernel::configfs::Attribute::new({ +/// const S: &str =3D "message\u{0}"; +/// const C: &kernel::str::CStr =3D match kernel::str::CSt= r::from_bytes_with_nul( +/// S.as_bytes(), +/// ) { +/// Ok(v) =3D> v, +/// Err(_) =3D> { +/// ::core::panicking::panic_fmt( +/// format_args!("string contains interior NUL= "), +/// ); +/// } +/// }; +/// C +/// }) +/// }; +/// unsafe { CONFIGURATION_ATTR_LIST.add::<0usize, 0u64, _>(&MESSA= GE_ATTR) } +/// static BAR_ATTR: kernel::configfs::Attribute< +/// 1u64, +/// Configuration, +/// Configuration, +/// > =3D unsafe { +/// kernel::configfs::Attribute::new({ +/// const S: &str =3D "bar\u{0}"; +/// const C: &kernel::str::CStr =3D match kernel::str::CSt= r::from_bytes_with_nul( +/// S.as_bytes(), +/// ) { +/// Ok(v) =3D> v, +/// Err(_) =3D> { +/// ::core::panicking::panic_fmt( +/// format_args!("string contains interior NUL= "), +/// ); +/// } +/// }; +/// C +/// }) +/// }; +/// unsafe { CONFIGURATION_ATTR_LIST.add::<1usize, 1u64, _>(&BAR_A= TTR) } +/// { +/// static CONFIGURATION_TPE: kernel::configfs::ItemType< +/// Subsystem, +/// Configuration, +/// > =3D kernel::configfs::ItemType::< +/// Subsystem, +/// Configuration, +/// >::new_with_child_ctor::<3usize, Child>(&THIS_MODULE, &CON= FIGURATION_ATTR_LIST); +/// &CONFIGURATION_TPE +/// } +/// }; +/// +#[cfg(CONFIG_CONFIGFS_FS)] +#[proc_macro] +pub fn configfs_attrs(input: TokenStream) -> TokenStream { + configfs_attrs::configfs_attrs(parse_macro_input!(input as configfs_at= trs::ConfigfsAttrs)) + .into() +} diff --git a/samples/rust/rust_configfs.rs b/samples/rust/rust_configfs.rs index a1bd9db6010da..876462f7789d1 100644 --- a/samples/rust/rust_configfs.rs +++ b/samples/rust/rust_configfs.rs @@ -4,7 +4,7 @@ =20 use kernel::alloc::flags; use kernel::configfs; -use kernel::configfs::configfs_attrs; +use kernel::macros::configfs_attrs; use kernel::new_mutex; use kernel::page::PAGE_SIZE; use kernel::prelude::*; --- base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731 change-id: 20260417-configfs-syn-191e07130027 Best regards, --=20 Malte Wechter