From: Greg KH <gregkh@linuxfoundation.org>
To: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Cc: alex.gaynor@gmail.com, bjorn3_gh@protonmail.com,
boqun.feng@gmail.com, gary@garyguo.net,
linux-kernel@vger.kernel.org, ojeda@kernel.org,
rust-for-linux@vger.kernel.org, wedsonaf@gmail.com
Subject: Re: [PATCH] rust: add this_module macro
Date: Tue, 31 Jan 2023 16:15:51 +0100 [thread overview]
Message-ID: <Y9kwpw18SVx9GZC4@kroah.com> (raw)
In-Reply-To: <20230131150745.370345-1-yakoyoku@gmail.com>
On Tue, Jan 31, 2023 at 12:07:45PM -0300, Martin Rodriguez Reboredo wrote:
> On Tue, Jan 31, 2023 at 02:42:08PM +0100, Greg KH wrote:
> >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
>
> This was meant for setting the owner field of a file_operations struct
> or the cra_owner field of crypto_alg and many other structs.
But shouldn't the macro kernel::declare_file_operations() do this for
you automagically? You should never have to manually say "this module!"
to any structure or function call if we do things right.
Yes, many "old school" structures in the kernel do this, but we have
learned from the 1990's, see the fun wrappers around simple things like
usb_register_driver(); as an example of how the driver author themselves
should never see a module pointer anywhere.
> I know that increfing a module without a good reason is dead dumb, so
> I'm not trying to send things in a downwards spiral. @@@
That's good, but let's not add housekeeping requirements when we do not
have to do so if at all possible please.
thanks,
greg k-h
next prev parent reply other threads:[~2023-01-31 15:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-31 13:08 [PATCH] rust: add this_module macro Martin Rodriguez Reboredo
2023-01-31 13:42 ` Greg KH
2023-01-31 15:07 ` Martin Rodriguez Reboredo
2023-01-31 15:15 ` Greg KH [this message]
2023-01-31 16:07 ` Martin Rodriguez Reboredo
2023-01-31 16:59 ` Greg KH
2023-01-31 20:46 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y9kwpw18SVx9GZC4@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
--cc=yakoyoku@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox