From: Petr Pavlu <petr.pavlu@suse.com>
To: John Garry <john.g.garry@oracle.com>
Cc: linux-modules@vger.kernel.org
Subject: Re: About THIS_MODULE
Date: Thu, 9 Jul 2026 16:31:41 +0200 [thread overview]
Message-ID: <79bba1c7-01f5-48ae-8b0d-07e4dcf0127a@suse.com> (raw)
In-Reply-To: <610fc63b-f3dc-4824-99fd-907fc96f3194@oracle.com>
On 7/3/26 5:33 PM, John Garry wrote:
> Hi all,
>
> I have a query which I hope someone can advise on.
>
> I am adding a library API which requires a driver to pass the driver module pointer to the API.
>
> So we use THIS_MODULE for that purpose.
>
> However, adding a sanity check in the library to ensure that pointer is set is a challenge. Normally we would check that the module pointer is non-NULL. However, for a built-in driver module, THIS_MODULE is NULL, so rely on the non-NULL check.
>
> Any idea how to deal with this?
Right, a NULL module pointer is ambiguous if you want to distinguish
between these two cases. I can't think of a neat way to handle this in
a library API.
One option would be to rework THIS_MODULE and introduce a reduced module
struct also for vmlinux and built-in modules. However, this isn't
a trivial change and I can't recall a case in the last few years where
this has caused a specific issue. Additionally, if someone forgets to
pass a module pointer somewhere, I would expect it to be fairly easy to
detect and fix.
--
Cheers,
Petr
prev parent reply other threads:[~2026-07-09 14:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 15:33 About THIS_MODULE John Garry
2026-07-09 14:31 ` Petr Pavlu [this message]
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=79bba1c7-01f5-48ae-8b0d-07e4dcf0127a@suse.com \
--to=petr.pavlu@suse.com \
--cc=john.g.garry@oracle.com \
--cc=linux-modules@vger.kernel.org \
/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