From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Ian Rogers <irogers@google.com>
Cc: Guenter Roeck <linux@roeck-us.net>,
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: Wed, 2 Dec 2026 08:28:00 +0200 [thread overview]
Message-ID: <fe80bb8c-1a6b-4119-a027-cf522fa76687@gmail.com> (raw)
In-Reply-To: <CAP-5=fX4D3__103FD=LFoUF1khdGEWthehyUi-GvS-=AbtYtyA@mail.gmail.com>
On 01/12/2026 20:02, Ian Rogers wrote:
> 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?
...
>>> 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
Oh well, I suppose one can't have everything. This is still much better
than nothing.
> 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.
Sounds great to me. If I read Guenter's reply (to other mail in this
thread) right, there aren't too many drivers which are built only
in-kernel so requiring explicit initialization also for them doesn't
sound bad to me.
The whole __must_init addition sounds good to me. Thanks for the lesson,
nice to have a new tool in the box :)
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductor
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
next prev parent reply other threads:[~2026-12-02 6:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
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:57 ` sashiko-bot
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 [this message]
2026-12-01 19:24 ` Guenter Roeck
2026-12-02 6:38 ` Matti Vaittinen
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 22:54 ` 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=fe80bb8c-1a6b-4119-a027-cf522fa76687@gmail.com \
--to=mazziesaccount@gmail.com \
--cc=irogers@google.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=llvm@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.