lkml.org 
[lkml]   [2023]   [Jan]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] rust: add this_module macro
On Tue, Jan 31, 2023 at 10:08:41AM -0300, Martin Rodriguez Reboredo wrote:
> Adds a Rust equivalent to the handy THIS_MODULE macro from C.
>
> Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
> ---
> rust/kernel/lib.rs | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index e0b0e953907d..afb6b0390426 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -80,6 +80,18 @@ impl ThisModule {
> }
> }
>
> +/// Returns the current module.
> +#[macro_export]
> +macro_rules! this_module {
> + () => {
> + if cfg!(MODULE) {
> + Some(unsafe { $crate::ThisModule::from_ptr(&mut $crate::bindings::__this_module) })
> + } else {
> + None
> + }
> + };
> +}

While this is handy, what exactly will it be used for? The C
wrappers/shim/whatever should probably handle this for you already when
you save this pointer into a structure right?

Surely you aren't trying to increment your own module's reference count,
right? That just doesn't work :)

thanks,

greg k-h

\
 
 \ /
  Last update: 2023-03-27 00:03    [W:0.044 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site