From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796193543; b=TaHJW/XPBbW8EFAyzFIc1iptLoFi7tv4YcPR13lcYtmHGD2Oa/pCoJo0kIlZM/Qgok57 +wBvLU1hf3HPdQ7mMPR7coW9uK6vy3OI7QXfAdeOKp3pApmH0u5s06AcHQTwdxwa2z28N qCZrdRiog3N3HvPzUjIjDvw3nBQMz9fVSghq2Q1vPHMGXep50+VjqNgyJ/gzdAfRV3c3w XCQ+zOVldKGa5v8kOWtNbjvha+r9yIs96BLd5+6v2EnsL90sHPmK5lOkd6XZm/lorKeQF usn163A4kjkRZ7bMdAnLg3g8GkA9FDIuCssUB+F8A/GTVT8JXBVK1j+cVbez+l+cSYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796193543; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=X4+Y4YVlDgU/iQIwgDcTbxa6Mdk0fgw6SkI9SFfRT+Q=; b=KWqQXxeysbq71/wFOXLU0Wb3/OgDNTi7YMNzKQNxyBLvX92ra+TA1grYJH8mrff0NQSS t+LkH6Vn9g+NFEDqEg2f3pPfgTExe+bupVBrxDPLG3fMVuikn7iPR39E1UCfwjT87wH22 aW6IweB3Ew8X5tikxPrxHIuasCJ353BmJfje/P4FkO5C9mgVGHbwRvTAd8re7Q4kOgKX6 YyQHd28llScI/ev7rvPpQ0ixqRzoWgA7/WVcuQogoJcxgHn7hDkQ55GPDGcwWEnN5Zof9 VJyecnUKw5IhrWinkbeazYdYKo9Uc78GS4WVpjbK4SKaqJazy4F3l7gWRfwNCggjhXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=j7wnwOqL; arc=none smtp.remote-ip=209.85.167.54 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04E53606A31A for ; Wed, 2 Dec 2026 06:39:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 04E53606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=j7wnwOqL Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5c148d4dbfbso10627919e87.3 for ; Tue, 01 Dec 2026 22:39:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796193541; x=1796798341; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=X4+Y4YVlDgU/iQIwgDcTbxa6Mdk0fgw6SkI9SFfRT+Q=; b=j7wnwOqLFXG0jIQGo2mIWxWwYv7u47rIY6u6p/+w0+aS9Yiv4KIB1HqlrMAm720Sat 3AvI6Id9TfZjOco6737tVJ8Xgok/Jwszum80JTMa6QncbS4wOwKbH7z+REEGNmfMPN0r ZGqQRIHgBWkWPaTwP0PQYmUTL5TPjCSsW40bSmiDawhg5E8O+d/phc2humQOaMX25fH+ hYOuchmZMM6eZJWXgz/FG5TKRn4D0B2EHXl48kD+1+GGFXTLlJuwghPPf3CTp5D5vOAD d2/wDd7jdl0x1oKfIZCCEKOQT1QFqu7PIndFgQ3EBdbpfJpuDWFOhb86RhfT4rgaV8EM qaQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796193541; x=1796798341; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=X4+Y4YVlDgU/iQIwgDcTbxa6Mdk0fgw6SkI9SFfRT+Q=; b=HO2/drcy3v52ZRwz5bXk3jycU0lK2rura9ndB6coREW07Rx4DfwveQwqvqqV4Xd9wJ vCkAJNIT1Iu8My6xpaWud15dC0TRKweQYw9W+vAb4cS3WPeTGg9XCs8lqjrZ2Bu+cASX DFFwsc9Cp2mg9mB84hM6W8HtCmoQXT97qo0cC1T1eIE689ru4rmNyompavjmAHhwvvnR KwMjFP3W6XVKfr/TNHaf46JWjXfHVCtU3ueLePu9i3YvvPmsbvAUJkAegUPAMNFyu9BB H1DcFxLDvZgTkW8jFozY6tPSusRxcNKiBcHMdZaH4+DW8eGW2whl3XN2E4vz6uvzquAA NVFg== X-Forwarded-Encrypted: i=1; AL+hErFOcYDOym1YR6HUyYqPzb/1D4Ruy+z8GnYimSJbg7DhzvdVHj5uEml25y4vaKa17EIRVeruqXVdXTh5lyJBew==@vger.kernel.org X-Gm-Message-State: APuU4Z+xYoZ+tIYkittNZS/4XrUTR9UyXHwIMWLmybPvTejXDutHmSa6 6OUv4yxSpnBzBd1HB0OZii932AolN7LZeRJT9+gd1WWNIH0nn9lCaX5z X-Gm-Gg: AZFdTZftaA2NiL3biw4yeppJ05WU3GYS1lp4Oz62iaWF+lCQXoSd1lPRO1b7V+qgpJ8 2D8aqbw3R3eALnGXYPejwWU4A8YM+C80ldrrAvtj0yAMmxaIe3uILTrBcr781dEpa/HZI2UHajZ JC20eHq5PBMjVWWQsv9u2RYMoSE1qdVClE5Z32/4XqkF+hCeJJc+SgU0965NIyBa8NQfg7/oiWO fiRbMgHEw3Ca0pyd0rWMcdoo+rHODR4U1V1VbEt05LmNdechGp35Jlz3ge4XjuDifSOrKlED4B7 vItLAdJx0t11o5dV08XiDhVgb4aBz7RSYhNEbhdDbhwDhSDisOwDkEkp/HngcptvfyymC7GvEuA l5W4wu+eUTreBt9B4G0S86ywOY+Rs9wkNgr1i2xhz3ZoHrC5Ue4pYfqeA07t6T0N6jorloukbGO 2JvhnR1QrFE4mlZmCkYMSW6caWGOpXR+T4T8SqDgiQQDW/cqurTmc/hNEOEURu4g00Ygi5K73QE RGOaDi+X/cI3sethElqZi+jOrUL36AIlaeo7fXDjMGQ9qdCmHVrHjSm85laC4a42A1fc6X87HYC LWuMHyF/GHMSwMtT27IjSKoI3y14157TGj26GJHaCSzNNhCo6Xd/O+EYn6voJTUJE5prq4IZSFK SmPechXQa X-Received: by 2002:a05:6512:3f03:b0:5bf:e7af:8db6 with SMTP id 2adb3069b0e04-5c1bc7c3b6bmr15056480e87.15.1796193540991; Tue, 01 Dec 2026 22:39:00 -0800 (PST) Received: from ?IPV6:2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703? ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3ae8044e3c4sm95994121fa.4.2026.12.01.22.39.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2026 22:39:00 -0800 (PST) Message-ID: Date: Wed, 2 Dec 2026 08:38:59 +0200 X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/5] watchdog: bd96801_wdt: Set .owner = THIS_MODULE in watchdog_ops To: Guenter Roeck , Ian Rogers Cc: Wim Van Sebroeck , Nathan Chancellor , linux-watchdog@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Lee Jones References: <20261130225410.98349-1-irogers@google.com> <20261130225410.98349-3-irogers@google.com> <91a23265-b2ae-4ed0-9593-d31d19a62b72@gmail.com> <122533eb-1d79-44d9-85c2-5b7977f02f08@roeck-us.net> <58ddcba6-d1be-4c4c-987d-eb7170dc716b@gmail.com> Content-Language: en-US, en-AU, en-GB, en-BW From: Matti Vaittinen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 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 >>>>> >>>>> Reviewed-by: Matti Vaittinen >>>>> >>>>> 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? 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). Yours, -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductor Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~