On Tue Sep 1, 2026 at 1:33 AM BST, Aaron Tomlin wrote:
> On Mon, Aug 17, 2026 at 04:51:58PM -0400, Aaron Tomlin wrote:
>> > > diff --git a/rust/macros/module.rs b/rust/macros/module.rs
>> > > index 06c18e207508..13353b43b38d 100644
>> > > --- a/rust/macros/module.rs
>> > > +++ b/rust/macros/module.rs
>> > > @@ -479,6 +479,7 @@ pub(crate) fn module(info: ModuleInfo) -> 
>> > > Result<TokenStream> {
>> > >      let ident_init = format_ident!("__{ident}_init");
>> > >      let ident_exit = format_ident!("__{ident}_exit");
>> > >      let ident_initcall = format_ident!("__{ident}_initcall");
>> > > +    let ident_modname = format_ident!("__{ident}_modname");
>> > >      let initcall_section = ".initcall6.init";
>> > >  
>> > >      let global_asm = format!(
>> > > @@ -590,6 +591,21 @@ pub extern "C" fn cleanup_module() {
>> > >                  #[cfg(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS)]
>> > >                  ::core::arch::global_asm!(#global_asm);
>> > >  
>> > > +                #[cfg(not(MODULE))]
>> > > +                #[repr(C)]
>> > > +                struct InitcallModname {
>> > > +                    initcall_fn: extern "C" fn() -> 
>> > > ::kernel::ffi::c_int,
>> > > +                    modname: *const ::kernel::ffi::c_char,
>> > > +                }
>> > > +
>> > > +                #[cfg(not(MODULE))]
>> > > +                #[used(compiler)]
>> > > +                #[link_section = ".initcall.modnames"]
>> > > +                static #ident_modname: InitcallModname = 
>> > > InitcallModname {
>> > 
>> > Can Rust directly use the C definition of initcall_modname via
>> > ::kernel::bindings::initcall_modname?
>> 
>> Well, defining the local '#[repr(C)] struct InitcallModname' follows the
>> existing precedents and avoids expanding the bindgen surface with
>> <linux/init.h>. I think this is preferred, no? Gary, any thoughts?
>> 
>> In rust/macros/module.rs the existing built-in initcall pointers are
>> defined directly within the macro rather than pulling in initcall_t from
>> bindings, keeping module.rs self-contained.

>
> Hi Gary,
>
> A gentle ping on this, to avoid holding up the series, shall we stick with
> this approach (i.e., keeping the local struct definition in the macro
> rather than expanding bindgen bindings)?
>
> If there are no objections, I'll proceed with this for the next revision.

Adding linux/init.h to the list of headers exported by bindgen is fine. Given
that this is a struct, I think Petr's suggestion to use generated bindings makes
sense.

Best,
Gary

Reply via email to