From: Guenter Roeck <linux@roeck-us.net>
To: Matti Vaittinen <mazziesaccount@gmail.com>,
Ian Rogers <irogers@google.com>
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>,
Nathan Chancellor <nathan@kernel.org>,
linux-watchdog@vger.kernel.org, llvm@lists.linux.dev,
linux-kernel@vger.kernel.org, Lee Jones <lee@kernel.org>
Subject: Re: [PATCH 2/5] watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops
Date: Tue, 1 Dec 2026 23:28:00 -0800 [thread overview]
Message-ID: <30e0059d-2e8f-4766-90c5-e7c810f92a75@roeck-us.net> (raw)
In-Reply-To: <af57a823-ea32-4e4e-ac44-c4b85fe6bad1@gmail.com>
On 12/1/26 22:38, Matti Vaittinen wrote:
> On 01/12/2026 21:24, Guenter Roeck wrote:
>> On 12/1/26 09:43, Matti Vaittinen 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().
>>>
>>
>> That would only work if watchdog_ops is not constant, and I really
>> would not want to change that.
>
> Right. I missed this. It makes sense to keep ops const. Thanks for the explanation. Let's drop this idea then.
>
>>
>> $ git grep "const struct watchdog_ops" | wc
>> 152 1059 12427
>>
>>> 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.
>>>
>>
>> Oh, I don't know. I would think this should be an acceptable burden
>> for the (I think) two watchdog drivers which must be built into
>> the kernel.
>
> You know it far better than me how requiring the .owner to be always populated impacts the drivers overall. I didn't know how common it is to only support building in the watchdog.
>
> I think there's still another problem. Looking at the init.h, we have:
>
> #ifdef MODULE
> extern struct module __this_module;
> #define THIS_MODULE (&__this_module)
> #else
> #define THIS_MODULE ((struct module *)0)
> #endif
>
> How to distinguish a case where the driver is configured to be built in "((struct module *)0)", from the case where the .owner is not set? Wouldn't the core check cause false alarms for all drivers when built in?
>
It ends up being a bit complicated. One way to do it would be to
actually introduce a shim macro as you had suggested, only use it to
validate .owner instead of setting it.
extern int _watchdog_register_device(struct watchdog_device *, struct module *);
#define watchdog_register_device(struct watchdog_device *wdd) \
_watchdog_register_device(wdd, THIS_MODULE)
and replace the existing watchdog_register_device() with
int _watchdog_register_device(struct watchdog_device *wdd, struct module *owner)
{
...
if (wdd->owner != owner)
return -EINVAL;
...
}
I am not sure if that would be worth the trouble, though.
> Anyways, adding the __must_init as suggested by Ian should help though. I've understood using Clang is quite popular (even though I still use gcc for a lot of my work).
>
Same here, but 0-day uses clang, so a failure to set .owner would
still be reported. Also, I am sure that Sashiko will pick this up pretty
quickly.
Thanks,
Guenter
next prev parent reply other threads:[~2026-12-02 7:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 22:54 [PATCH 0/5] watchdog: Set missing " 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-12-01 19:44 ` Guenter Roeck
2026-12-02 6:28 ` Matti Vaittinen
2026-12-01 19:24 ` Guenter Roeck
2026-12-02 6:38 ` Matti Vaittinen
2026-12-02 7:28 ` Guenter Roeck [this message]
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
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=30e0059d-2e8f-4766-90c5-e7c810f92a75@roeck-us.net \
--to=linux@roeck-us.net \
--cc=irogers@google.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mazziesaccount@gmail.com \
--cc=nathan@kernel.org \
--cc=wim@linux-watchdog.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
all inboxes | Powered by JetHome®