Linux Modules
 help / color / mirror / Atom feed
* About THIS_MODULE
@ 2026-07-03 15:33 John Garry
  2026-07-09 14:31 ` Petr Pavlu
  0 siblings, 1 reply; 2+ messages in thread
From: John Garry @ 2026-07-03 15:33 UTC (permalink / raw)
  To: linux-modules

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?

Cheers

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: About THIS_MODULE
  2026-07-03 15:33 About THIS_MODULE John Garry
@ 2026-07-09 14:31 ` Petr Pavlu
  0 siblings, 0 replies; 2+ messages in thread
From: Petr Pavlu @ 2026-07-09 14:31 UTC (permalink / raw)
  To: John Garry; +Cc: linux-modules

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-09 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-03 15:33 About THIS_MODULE John Garry
2026-07-09 14:31 ` Petr Pavlu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox