Re: [PATCH 2/5] watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops

From: Guenter Roeck

Date: Tue Dec 01 2026 - 14:44:50 EST


On 12/1/26 10:02, Ian Rogers wrote:
On Tue, Dec 1, 2026 at 9:43 AM Matti Vaittinen <mazziesaccount@xxxxxxxxx> wrote:

On 01/12/2026 19:19, Ian Rogers wrote:
On Tue, Dec 1, 2026 at 8:19 AM Guenter Roeck <linux@xxxxxxxxxxxx> wrote:

On 12/1/26 00:03, Matti Vaittinen wrote:
On 01/12/2026 00:54, Ian Rogers wrote:
watchdog_open() calls try_module_get(wdd->ops->owner) to prevent the
watchdog driver module from being unloaded while /dev/watchdog is open,
and watchdog_release() calls module_put(wdd->ops->owner). Because
try_module_get(NULL) succeeds without incrementing any module reference
count, omitting .owner = THIS_MODULE allows the module to be unloaded
while the watchdog character device is open.

Set .owner = THIS_MODULE in bd96801_wdt_ops, found with Clang's
require_explicit_initialization attribute.

Fixes: 09dad69757b6 ("watchdog: ROHM BD96801 PMIC WDG driver")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>

Reviewed-by: Matti Vaittinen <mazziesaccount@xxxxxxxxx>

Thanks a lot!

This made me wonder, would it be possible to do some macro-magic so the .owner was automatically set upon driver registration to wdg-core, when driver is built as a module?


Possibly, either by defining a macro such as DEFINE_WATCHDOG_OPS,
or by moving ownership out of watchdog_ops (no idea though if/how
that might work, and it sounds complicated).

I was thinking something like renaming
devm_watchdog_register_device() to
__devm_watchdog_register_device()

and adding a macro
#define devm_watchdog_register_device(...)

which fills the .owner with THIS_MODULE and calls the
__devm_watchdog_register_device().

Not sure how big of a hassle that would be though.


It might be simpler to just add a check into the watchdog core
and ensure that the owner is set when a watchdog is registered.

I was considering this but if I understand it right, omitting setting
the .owner is legitimate when driver is built-in. I couldn't figure out
how the core could check if driver doing the registration was built as a
module.


Hi Matti, Guenter,

Thanks for the review and for applying the series (and fixing up the
extra Fixes tag on patch 1)!

For preventing missing .owner in struct watchdog_ops going forward:
__must_init (wrapping Clang's require_explicit_initialization attribute)
just landed in driver-core-next / linux-next for v7.5:
https://lore.kernel.org/lkml/20261119192520.1983406-1-irogers@xxxxxxxxxx/

Once that reaches v7.5-rc1, adding __must_init to
struct watchdog_ops::owner will catch any driver that omits .owner at
compile time on Clang 20+, including built-in or unprobed drivers where
a runtime check on registration wouldn't catch a NULL owner. I can send
that one-line follow-up patch once the macro is in mainline.


Please do, and while at it please also mark `start` as mandatory.

Does this work if there are drivers which can't be build as modules, and
which are omitting the initialization (assuming that's allowed)? If yes,
I am all for it. Do you know if there is a gcc equivalent?

Sadly there isn't a gcc equivalent yet. With __must_init you can't
omit the initialization but you can initialize to NULL, which at least
requires a conscious decision that you want to omit the
initialization. You can use __must_init on structs in kernel and
module code.


I am really not concerned about watchdog drivers which must be built into
the kernel. AFAICS there are two of them. One (MPC5200_WDT) is not using
the watchdog subsystem, and the other (RTD119X_WATCHDOG) already initializes
.owner. THIS_MODULE is NULL for drivers built into the kernel, so
the worst additional burden on driver developers would be the need
to explicitly add ".owner = THIS_MODULE," to the driver.

Thanks,
Guenter