From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796193543; b=es0zpwfgT72o4E31TOCVbp6L+ZnL0ty5y1pOEL7j9u9PI2Od4hxKXALK5FgAy0E6dvUY 6k7DeWku2mKx2ZIkWf3yoPC2zFG28pV9Tmmo8ez9o1d3wBcw5ksu+E/bZQUMY0rB1ndFf QF3+OWpkZ1fZ0/TPzyyFbHqUhmzz6EE1hITVhiYMcC+G2iLsHFhYY3usKSRTYqGSAxajb HHDmzrPWte84mAqzuKBNYGyiIHjZnZSfNBtA1Zbi3yBIaGxxPoYeF3VDdQB5LTKMvJrlX oejvgr1Z8AYEPYWKBaPVEIR0U9Fq+riNn+h03SVSMxE9EjLed1w0zbKNyRNENw0EKxA== 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=Mt0uDrvK1tZEMMdOztJViloC2Akag4esTk/+Rnh/S3KR2CGlNx7JZrmSe4Q8e78pI3JJ psHeiiuPq3ia/dHJ9G4W0pbtJzp5eNHX8QhggAFdJuKhKD3f7pY8P/Q2nrkh5nk5Bgy7A Do74DHLkHbzBuj7mGvplf3r4FojBQU8fBEtMJkMPf4uNY+iMzKzZudv29vIq+2NFt4BHF YkHX1eUbrNz8NFFryzj+d4VMRGTSnjw72c4Gt/tO92/Dk00dLyQF70P0lI7xiPQMDtguC 4ljMDXmYDguuEt3Xb46/TI5SYOIdMXB7dDt/peaP+7qNuahxJofWvlIMW7yMzC8IOZQ== 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.47 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 2D4EA606A322 for ; Wed, 2 Dec 2026 06:39:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2D4EA606A322 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-f47.google.com with SMTP id 2adb3069b0e04-5be3cff0f6cso8685595e87.0 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=LlOwrdcDPoMxjbkxRjkn7ozmROimjhlI6UpxeXzaH+ix4ppYfoSSIqaDW1kJgRizSu 4oar4FMFkPwCBuXi3GrZu3MtULEuPVQAfIr7xmucYGLhaMdvmYvv76DfGkFwlQrUyy3/ dJjXiYX3DfrwGVTrmdh7YcVkfwhrWPXQ+yAi+MdU6tLJsj1WVfaVn30Q04qDlQfN2jvr Fb93Pc2TKBTVg/bM9N7SqaKuLiBReC1pjrNnNCQc4kO9m0RM4N4mADUQvPcjnd7r5OrJ M7/dzQGsrBQGsgimFoae8BIAc5EL7B5C4+SveQcGVNOhiSGpxDfLEhgJ0dfQNu8qB0qY R6jw== X-Forwarded-Encrypted: i=1; AL+hErHhblxTN7q0WWXEuYZ9iGEDM2nkcQtFGOsUXKfXVfFZ8R/fo/u0zvhnsFtvrJAlTRE3xFGxyvLEhhaLlCQ=@vger.kernel.org X-Gm-Message-State: APuU4Z9/4amaM79+aJFqn1OjKWDTJsgXmhUWhNbZtLyQieT0vxnGv0MK CWw9huHPlvE2xpEajIIhZ0OMkeYGV0K1y3XiVDni9e1gpFQXPM2vaKyU X-Gm-Gg: AZFdTZcv6hOrlXXK+EurXntotAFAEb+rFfuQ3ZDi6lRtPI1zrh98GpqlVEYq3Xljmou S0j8oMET/jmp34GDCGI6flJahLAVCNNCOzAsFsTmHATSXl/JjKqP5zpJlHubXFlxJa/PPwB0nFK 4zawn35qH5wUYaNfEpo02avpp2/pG4MeyQDAGMNm9ar6YMR3i5PLJ8In7M27F+O115qoZ+Nxtp/ efCPJRSYPybrreLp+9YPa0DTZxOcBxu/rRLvckBErx15gnvE/FEONU6Qp48a8mtIepbyYLQ4cIs LA944CzDDEe8ur0EexUZL68Ia6WeKIKVtvTnlfO5FBWDg2ptj7DAV/5GS7kzOKf8QHNgtYdCyFw I0Ip5KyuEUGzTTC/IBwpUQMkyD9hf3htCVS+XLuy28l7EHKTkjiG3HzsqG32ggYKJ0UVEjdATd2 rBUYCCYIRpklw+rJqqkTx8KgiVL/+hUIl6W7dbORY8Jom1gJSvU+dAOaCgWPiu5YXv4Igeq09zk oailiXFhcSSS7vUda0O8SlA4+ZcaJ8aT5sawopsHbdSJmb42+LB86BXsqaLA0cDePTg3ge0Sk21 AKQy+8WIY1D5OMXNt/5QpxhmqFY+J2ai1hIH/tIbetcnSqBEc/9ZBhgNKvLMS+gH00zkZ25huAI pdHrUnL91 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-kernel@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! ~~