* [PATCH 0/5] watchdog: Set missing .owner = THIS_MODULE in watchdog_ops
@ 2026-11-30 22:54 Ian Rogers
2026-11-30 22:54 ` [PATCH 1/5] watchdog: arm_smc_wdt: Set " Ian Rogers
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Ian Rogers @ 2026-11-30 22:54 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck
Cc: Nathan Chancellor, linux-watchdog, llvm, linux-kernel, Ian Rogers
watchdog_open() calls try_module_get(wdd->ops->owner) so a modular
watchdog driver cannot be unloaded while /dev/watchdog is open. Five
modular watchdog drivers omit .owner = THIS_MODULE in their const struct
watchdog_ops definitions, leaving wdd->ops->owner NULL.
Split per driver to simplify review and stable backporting.
Tooling note: Found using Clang's require_explicit_initialization
attribute; an AI coding assistant helped audit call sites, verify Fixes
commits, and draft the changelogs. All five drivers were build-tested as
modules (-DMODULE) with LLVM=1.
Ian Rogers (5):
watchdog: arm_smc_wdt: Set .owner = THIS_MODULE in watchdog_ops
watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops
watchdog: ebc-c384_wdt: Set .owner = THIS_MODULE in watchdog_ops
watchdog: max77620: Set .owner = THIS_MODULE in watchdog_ops
watchdog: meson_gxbb_wdt: Set .owner = THIS_MODULE in watchdog_ops
drivers/watchdog/arm_smc_wdt.c | 2 ++
drivers/watchdog/bd96801_wdt.c | 1 +
drivers/watchdog/ebc-c384_wdt.c | 1 +
drivers/watchdog/max77620_wdt.c | 1 +
drivers/watchdog/meson_gxbb_wdt.c | 1 +
5 files changed, 6 insertions(+)
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/5] watchdog: arm_smc_wdt: Set .owner = THIS_MODULE in watchdog_ops
2026-11-30 22:54 [PATCH 0/5] watchdog: Set missing .owner = THIS_MODULE in watchdog_ops Ian Rogers
@ 2026-11-30 22:54 ` Ian Rogers
2026-11-30 22:54 ` [PATCH 2/5] watchdog: bd96801_wdt: " Ian Rogers
` (4 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Ian Rogers @ 2026-11-30 22:54 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck
Cc: Nathan Chancellor, linux-watchdog, llvm, linux-kernel, Ian Rogers,
Julius Werner, Evan Benn, Antonio Borneo
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 smcwd_ops and smcwd_timeleft_ops, found with
Clang's require_explicit_initialization attribute.
Fixes: 72a9e7fea586 ("watchdog: Add new arm_smc_wdt watchdog driver")
Fixes: cc0df5eba1b3 ("watchdog: arm_smc_wdt: get wdt status through SMCWD_GET_TIMELEFT")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/watchdog/arm_smc_wdt.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/watchdog/arm_smc_wdt.c b/drivers/watchdog/arm_smc_wdt.c
index 479863450a9c..e593ee8f23c0 100644
--- a/drivers/watchdog/arm_smc_wdt.c
+++ b/drivers/watchdog/arm_smc_wdt.c
@@ -97,6 +97,7 @@ static const struct watchdog_info smcwd_info = {
};
static const struct watchdog_ops smcwd_ops = {
+ .owner = THIS_MODULE,
.start = smcwd_start,
.stop = smcwd_stop,
.ping = smcwd_ping,
@@ -104,6 +105,7 @@ static const struct watchdog_ops smcwd_ops = {
};
static const struct watchdog_ops smcwd_timeleft_ops = {
+ .owner = THIS_MODULE,
.start = smcwd_start,
.stop = smcwd_stop,
.ping = smcwd_ping,
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/5] watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops
2026-11-30 22:54 [PATCH 0/5] watchdog: Set missing .owner = THIS_MODULE in watchdog_ops Ian Rogers
2026-11-30 22:54 ` [PATCH 1/5] watchdog: arm_smc_wdt: Set " Ian Rogers
@ 2026-11-30 22:54 ` Ian Rogers
2026-12-01 8:03 ` Matti Vaittinen
2026-11-30 22:54 ` [PATCH 3/5] watchdog: ebc-c384_wdt: " Ian Rogers
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Ian Rogers @ 2026-11-30 22:54 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck
Cc: Nathan Chancellor, linux-watchdog, llvm, linux-kernel, Ian Rogers,
Matti Vaittinen, Lee Jones
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@google.com>
---
drivers/watchdog/bd96801_wdt.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/watchdog/bd96801_wdt.c b/drivers/watchdog/bd96801_wdt.c
index ce93a900b0be..38d14b22b09d 100644
--- a/drivers/watchdog/bd96801_wdt.c
+++ b/drivers/watchdog/bd96801_wdt.c
@@ -94,6 +94,7 @@ static const struct watchdog_info bd96801_wdt_info = {
};
static const struct watchdog_ops bd96801_wdt_ops = {
+ .owner = THIS_MODULE,
.start = bd96801_wdt_start,
.stop = bd96801_wdt_stop,
.ping = bd96801_wdt_ping,
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/5] watchdog: ebc-c384_wdt: Set .owner = THIS_MODULE in watchdog_ops
2026-11-30 22:54 [PATCH 0/5] watchdog: Set missing .owner = THIS_MODULE in watchdog_ops Ian Rogers
2026-11-30 22:54 ` [PATCH 1/5] watchdog: arm_smc_wdt: Set " Ian Rogers
2026-11-30 22:54 ` [PATCH 2/5] watchdog: bd96801_wdt: " Ian Rogers
@ 2026-11-30 22:54 ` Ian Rogers
2026-11-30 22:54 ` [PATCH 4/5] watchdog: max77620: " Ian Rogers
` (2 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Ian Rogers @ 2026-11-30 22:54 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck
Cc: Nathan Chancellor, linux-watchdog, llvm, linux-kernel, Ian Rogers,
William Breathitt Gray
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 ebc_c384_wdt_ops, found with Clang's
require_explicit_initialization attribute.
Fixes: c36a483d8007 ("watchdog: Add watchdog timer support for the WinSystems EBC-C384")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/watchdog/ebc-c384_wdt.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/watchdog/ebc-c384_wdt.c b/drivers/watchdog/ebc-c384_wdt.c
index c80a28b09de0..e931f43bcc3f 100644
--- a/drivers/watchdog/ebc-c384_wdt.c
+++ b/drivers/watchdog/ebc-c384_wdt.c
@@ -78,6 +78,7 @@ static int ebc_c384_wdt_set_timeout(struct watchdog_device *wdev, unsigned t)
}
static const struct watchdog_ops ebc_c384_wdt_ops = {
+ .owner = THIS_MODULE,
.start = ebc_c384_wdt_start,
.stop = ebc_c384_wdt_stop,
.set_timeout = ebc_c384_wdt_set_timeout
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/5] watchdog: max77620: Set .owner = THIS_MODULE in watchdog_ops
2026-11-30 22:54 [PATCH 0/5] watchdog: Set missing .owner = THIS_MODULE in watchdog_ops Ian Rogers
` (2 preceding siblings ...)
2026-11-30 22:54 ` [PATCH 3/5] watchdog: ebc-c384_wdt: " Ian Rogers
@ 2026-11-30 22:54 ` Ian Rogers
2026-11-30 22:54 ` [PATCH 5/5] watchdog: meson_gxbb_wdt: " Ian Rogers
2026-11-30 23:10 ` [PATCH 0/5] watchdog: Set missing " Guenter Roeck
5 siblings, 0 replies; 12+ messages in thread
From: Ian Rogers @ 2026-11-30 22:54 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck
Cc: Nathan Chancellor, linux-watchdog, llvm, linux-kernel, Ian Rogers,
Laxman Dewangan
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 max77620_wdt_ops, found with Clang's
require_explicit_initialization attribute.
Fixes: ff3bb2f5c3cd ("watchdog: max77620: Add support for watchdog timer")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/watchdog/max77620_wdt.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/watchdog/max77620_wdt.c b/drivers/watchdog/max77620_wdt.c
index 4fc8a858d221..ad2b497f7c9a 100644
--- a/drivers/watchdog/max77620_wdt.c
+++ b/drivers/watchdog/max77620_wdt.c
@@ -148,6 +148,7 @@ static const struct watchdog_info max77620_wdt_info = {
};
static const struct watchdog_ops max77620_wdt_ops = {
+ .owner = THIS_MODULE,
.start = max77620_wdt_start,
.stop = max77620_wdt_stop,
.ping = max77620_wdt_ping,
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 5/5] watchdog: meson_gxbb_wdt: Set .owner = THIS_MODULE in watchdog_ops
2026-11-30 22:54 [PATCH 0/5] watchdog: Set missing .owner = THIS_MODULE in watchdog_ops Ian Rogers
` (3 preceding siblings ...)
2026-11-30 22:54 ` [PATCH 4/5] watchdog: max77620: " Ian Rogers
@ 2026-11-30 22:54 ` Ian Rogers
2026-11-30 23:10 ` [PATCH 0/5] watchdog: Set missing " Guenter Roeck
5 siblings, 0 replies; 12+ messages in thread
From: Ian Rogers @ 2026-11-30 22:54 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck
Cc: Nathan Chancellor, linux-watchdog, llvm, linux-kernel, Ian Rogers,
Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
linux-arm-kernel, linux-amlogic
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 meson_gxbb_wdt_ops, found with Clang's
require_explicit_initialization attribute.
Fixes: 683fa50f0e18 ("watchdog: Add Meson GXBB Watchdog Driver")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/watchdog/meson_gxbb_wdt.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c
index a88fe8cbeef5..7ee8632eba36 100644
--- a/drivers/watchdog/meson_gxbb_wdt.c
+++ b/drivers/watchdog/meson_gxbb_wdt.c
@@ -108,6 +108,7 @@ static unsigned int meson_gxbb_wdt_get_timeleft(struct watchdog_device *wdt_dev)
}
static const struct watchdog_ops meson_gxbb_wdt_ops = {
+ .owner = THIS_MODULE,
.start = meson_gxbb_wdt_start,
.stop = meson_gxbb_wdt_stop,
.ping = meson_gxbb_wdt_ping,
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] watchdog: Set missing .owner = THIS_MODULE in watchdog_ops
2026-11-30 22:54 [PATCH 0/5] watchdog: Set missing .owner = THIS_MODULE in watchdog_ops Ian Rogers
` (4 preceding siblings ...)
2026-11-30 22:54 ` [PATCH 5/5] watchdog: meson_gxbb_wdt: " Ian Rogers
@ 2026-11-30 23:10 ` Guenter Roeck
5 siblings, 0 replies; 12+ messages in thread
From: Guenter Roeck @ 2026-11-30 23:10 UTC (permalink / raw)
To: Ian Rogers, Wim Van Sebroeck
Cc: Nathan Chancellor, linux-watchdog, llvm, linux-kernel
Hi Ian,
On 11/30/26 14:54, Ian Rogers wrote:
> watchdog_open() calls try_module_get(wdd->ops->owner) so a modular
> watchdog driver cannot be unloaded while /dev/watchdog is open. Five
> modular watchdog drivers omit .owner = THIS_MODULE in their const struct
> watchdog_ops definitions, leaving wdd->ops->owner NULL.
>
> Split per driver to simplify review and stable backporting.
>
> Tooling note: Found using Clang's require_explicit_initialization
> attribute; an AI coding assistant helped audit call sites, verify Fixes
> commits, and draft the changelogs. All five drivers were build-tested as
> modules (-DMODULE) with LLVM=1.
>
> Ian Rogers (5):
> watchdog: arm_smc_wdt: Set .owner = THIS_MODULE in watchdog_ops
> watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops
> watchdog: ebc-c384_wdt: Set .owner = THIS_MODULE in watchdog_ops
> watchdog: max77620: Set .owner = THIS_MODULE in watchdog_ops
> watchdog: meson_gxbb_wdt: Set .owner = THIS_MODULE in watchdog_ops
Series applied. Note that I dropped the second Fixes: tag from the first
patch as suggested by Sashiko.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops
2026-11-30 22:54 ` [PATCH 2/5] watchdog: bd96801_wdt: " Ian Rogers
@ 2026-12-01 8:03 ` Matti Vaittinen
2026-12-01 16:19 ` Guenter Roeck
0 siblings, 1 reply; 12+ messages in thread
From: Matti Vaittinen @ 2026-12-01 8:03 UTC (permalink / raw)
To: Ian Rogers, Wim Van Sebroeck, Guenter Roeck
Cc: Nathan Chancellor, linux-watchdog, llvm, linux-kernel, Lee Jones
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@google.com>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
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?
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops
2026-12-01 8:03 ` Matti Vaittinen
@ 2026-12-01 16:19 ` Guenter Roeck
2026-12-01 17:19 ` Ian Rogers
0 siblings, 1 reply; 12+ messages in thread
From: Guenter Roeck @ 2026-12-01 16:19 UTC (permalink / raw)
To: Matti Vaittinen, Ian Rogers, Wim Van Sebroeck
Cc: Nathan Chancellor, linux-watchdog, llvm, linux-kernel, Lee Jones
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@google.com>
>
> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
>
> 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).
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.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops
2026-12-01 16:19 ` Guenter Roeck
@ 2026-12-01 17:19 ` Ian Rogers
2026-12-01 17:43 ` Matti Vaittinen
0 siblings, 1 reply; 12+ messages in thread
From: Ian Rogers @ 2026-12-01 17:19 UTC (permalink / raw)
To: Guenter Roeck
Cc: Matti Vaittinen, Wim Van Sebroeck, Nathan Chancellor,
linux-watchdog, llvm, linux-kernel, Lee Jones
On Tue, Dec 1, 2026 at 8:19 AM Guenter Roeck <linux@roeck-us.net> 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@google.com>
> >
> > Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
> >
> > 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).
>
> 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.
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@google.com/
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.
Thanks,
Ian
> Thanks,
> Guenter
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops
2026-12-01 17:19 ` Ian Rogers
@ 2026-12-01 17:43 ` Matti Vaittinen
2026-12-01 18:02 ` Ian Rogers
0 siblings, 1 reply; 12+ messages in thread
From: Matti Vaittinen @ 2026-12-01 17:43 UTC (permalink / raw)
To: Ian Rogers, Guenter Roeck
Cc: Wim Van Sebroeck, Nathan Chancellor, linux-watchdog, llvm,
linux-kernel, Lee Jones
On 01/12/2026 19:19, Ian Rogers wrote:
> On Tue, Dec 1, 2026 at 8:19 AM Guenter Roeck <linux@roeck-us.net> 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@google.com>
>>>
>>> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
>>>
>>> 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@google.com/
>
> 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.
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?
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops
2026-12-01 17:43 ` Matti Vaittinen
@ 2026-12-01 18:02 ` Ian Rogers
0 siblings, 0 replies; 12+ messages in thread
From: Ian Rogers @ 2026-12-01 18:02 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Guenter Roeck, Wim Van Sebroeck, Nathan Chancellor,
linux-watchdog, llvm, linux-kernel, Lee Jones
On Tue, Dec 1, 2026 at 9:43 AM Matti Vaittinen <mazziesaccount@gmail.com> wrote:
>
> On 01/12/2026 19:19, Ian Rogers wrote:
> > On Tue, Dec 1, 2026 at 8:19 AM Guenter Roeck <linux@roeck-us.net> 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@google.com>
> >>>
> >>> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
> >>>
> >>> 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@google.com/
> >
> > 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.
>
> 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.
Thanks,
Ian
> Yours,
> -- Matti
>
> --
> Matti Vaittinen
> Linux kernel developer at ROHM Semiconductor
> Oulu Finland
>
> ~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-12-01 18:02 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 22:54 [PATCH 0/5] watchdog: Set missing .owner = THIS_MODULE in watchdog_ops Ian Rogers
2026-11-30 22:54 ` [PATCH 1/5] watchdog: arm_smc_wdt: Set " Ian Rogers
2026-11-30 22:54 ` [PATCH 2/5] watchdog: bd96801_wdt: " Ian Rogers
2026-12-01 8:03 ` Matti Vaittinen
2026-12-01 16:19 ` Guenter Roeck
2026-12-01 17:19 ` Ian Rogers
2026-12-01 17:43 ` Matti Vaittinen
2026-12-01 18:02 ` Ian Rogers
2026-11-30 22:54 ` [PATCH 3/5] watchdog: ebc-c384_wdt: " Ian Rogers
2026-11-30 22:54 ` [PATCH 4/5] watchdog: max77620: " Ian Rogers
2026-11-30 22:54 ` [PATCH 5/5] watchdog: meson_gxbb_wdt: " Ian Rogers
2026-11-30 23:10 ` [PATCH 0/5] watchdog: Set missing " Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox