On 1/10/26 4:08 PM, Kari Argillander wrote: > To make clear separation between module crates and kernel crate we > introduce ThisModule trait which is meant to be used by kernel space. > THIS_MODULE is meant to be used by modules. So kernel create will be > unable to even accidentally use THIS_MODULE. > > As ThisModule is trait we can pass that around in const context. This is > needed so that we can read ownership information in const context when > we create example file_operations structs for modules. > > New ThisModule will also eventually replace kernel::ModuleMetadata trait > and for this reason it also have NAME field. > > To make transition smooth use mod this_module so we can have two > ThisModule same time. Also some functionality is added to THIS_MODULE > temporarily so that we do not have to change everything at once. > > Also docs examples will need THIS_MODULE so also define that in docs. > > Signed-off-by: Kari Argillander <[email protected]>
Is this pattern common in other Rust code in the kernel? The situation on the C side is that THIS_MODULE is a variable of the module struct. On the Rust side, it is currently quite similar, with THIS_MODULE being a variable of the ThisModule struct/wrapper. The patch shifts this and makes THIS_MODULE a type that implements the ThisModule trait. Naively, it seems somewhat confusing to me, coming mostly from the C side and expecting THIS_MODULE to be a variable. I'd like to understand this better. Would enabling const_refs_to_static alone be sufficient, or is it necessary to make THIS_MODULE a type for this to work? Should we be concerned that this new model could confuse people, or do you think it actually simplifies things? Does making the functions generic on ThisModule impact code size in any significant way, or could it in the future? -- Thanks, Petr

