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=1796147039; b=hKeVmNFpGwvxkPpZpQRUkFqKPKBnGzEOHXu2SbdeXzC7qTwdyxmEGm6BPxrB+fFEOMv3 212shR1lfrjUVL8ym5j7TPczsJyTxOEcGkDw1NNN1u1bbaoEibW3q7PcsHgZoVK5F+RNN 6naL3kpSgIUE/c7mhbNUIo+aYa8mSvLTmm+hqI+CyPtVIb9BJp/db7Jc6l0qMPiR8XOgo UDzu7MLRJSnn5FBKiVjrv9fgbO4whwJ4+6bP4lgfJAmHnuJ3IHeIYMbFHzvhJv/2u3fYZ iTlpm/+6LXyDyiursAV3wEdAK7yPjE1Ugx9PBmfNb0Wpd87lZkAIZtDQ7j0VT/tBKxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147039; 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=F2PJFf4WfqXxB1k0B05Txy6f1J8jTGdt+SmEEMsG0AY=; b=a4c011sV5iQXmNdus/s/mZpeVRbDkBsZudU0k6I7Ulxh9SZpMJytvZ0S6GyIOyszwFZX 6oDbQSnJl5RJL5ERB96fP5cUONEVXH9yaRmKIUd46YK9e5d4Sk6oFTO9fxrTrJ4Esput9 bI4P1fzhCRBriHKdvyoBCIC3aF3jH5nRY0QvtkwZyWud4Ja/mCIi4d+6eYy00lVeG89L0 Lw/SAsETIj3rsoJFjqJ1GyTEiTfwh6KmVGbVS+OOA0ZvBqswPsoWdalIWghoAJcWuSucX 9bm0qH0eEQWMPiVEQP3In/VI/r1w4AUhKbtHhQvaupU1ATH+r9n11qXXwLuJB0WW9rQ== 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=SE7N1VnX; 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 6B0B4606A68E for ; Tue, 1 Dec 2026 17:43:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6B0B4606A68E 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=SE7N1VnX Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5c3683680edso617672e87.1 for ; Tue, 01 Dec 2026 09:43:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796147038; x=1796751838; darn=lists.linux.dev; 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=F2PJFf4WfqXxB1k0B05Txy6f1J8jTGdt+SmEEMsG0AY=; b=SE7N1VnXzSGB97933Z4s/h6A9EDZ8eUvfLy/vdk87y+G7ulzLLdgBrlKXv0jJKhWlg 7F1lYSi0r3erqVoRhribXvxOriSSgqnwDCMR6mg9m4ULdnxUcqCDChHw0uuC/0M06MC/ UlAOJDLt59UkAIdYx2tmpwvHOsru7Bf3tWTkH53f1LmVPBs3t5wfiBsH7XKre/SdmXM/ s/o2XRhi5yf54OOs90jqerCti1UijTzGXly5YP8O3z4+ZwanjYA5RtVyRb6e8OnLbKnr U2jp2oCPf/Hvk3mAqjnFU4FqVCEtaz6R4YgWmrkOiLGAH9X+qBtC8ENc6PDHrLdGCgp4 6EmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796147038; x=1796751838; 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=F2PJFf4WfqXxB1k0B05Txy6f1J8jTGdt+SmEEMsG0AY=; b=f9RcGBPanwyEpXk2tpDaNyvH12xw5ILhTs3T5ijAFQ/t7b1Bjb4Q3qBdPLtu/LwQBN NooQ+Q8n3UkTuAF04c7yBbKnNQpJrXqc9B8Cjcmen7gLfqVEyoI64puZePTxe88YtXv0 qMjSHth9/oNEBbmfPeWuJFZPlxuGBNv16uyGKB8B0KuXDo3TpYwPPFesnVy2RUP40n4W oJBGkkKWLkQdAdy4mik35+6k5e0LPgb9+/FX3M6PZtdf1qwNhlQeMmv7LCnS2pgocKrt XAQdhsXp7t7GavMBWh0VJCMtKlwdma8wt4Sw/ovBpl1QViSgQS2PLNAk45ZOZX/sDpiI 1pLQ== X-Forwarded-Encrypted: i=1; AL+hErEfEQVcJB7kSkQPubnKJcQbTOOR0n/cRfhUAS7lwF2EyAUNL6bPra2g0jim5sJ04P4GzURU@lists.linux.dev X-Gm-Message-State: APuU4Z9/CuJR9huqH/5heaQwEcei/EWyahTrX8Dtxuet4t6DoHlQoKH2 +I7E+MtEZlCrmaIbTf3FH9c1R9lJsRPSI/pHnLfGqIpuJe4kYf8uO08h5gfuChJk X-Gm-Gg: AZFdTZc7luqbMaCzsjx7eGa7oBg7ezyWDSQVxqbhkpHYugx+FpjyHbkI4GmRPhiJtzg 9jChir5YtiOV2+/VPWp5sGZvNNQBBMaq12xRktzx1tIeBePgwyQ5vGYbkTaeFzVyPPynEbDy6O+ zVtlV0Kvz4kICAdwXCmvTC253LxNy1BU9YRf4bbwMF+u2Dfbtm9I1toAWyFIQe2N5UwRuRINb+Z 0+XGW2eFMxdNlrbx5ak13vhYGVHQ+bbfeBQM8p4o6SbBlIAnyCMdzEZVuND8gg+iu0hcG5ieTtT dgdlqgSJNmgbEKw5L/bZGL1Qej98fcbBlFVdmlBT/l62sipzJfQuN9WDNpFkOhSvo276Bqvnhy3 wY6m8L2xVw4gjssEnu83Bfi22To977Aa7DV7jKfKJTD1wo/WVLU8vUiIH0jspHgPV0kZsnfr4M8 7vZRjau/+xeG3qiDOi+vpURhPql7kq4eI6Y3AB4kOWRH73+5PrVa/kFYXfle4zKk53M4y4yPQgZ s4wWNc+8ZVZp7xDY4bwavTnWVtFhg+hrbMW+ZJSLyKhRCQXdQQ/wGrRwUa5m66mzdDSEoE8VbK5 asC1+0rSMQbYelnrpLGQHzfmJ9W4a2RPuPs5Li/g8TJTQtwR3nzi0MP8w6gLUVmWsfIhH7ZH48z osKyJh5dIMUKA7uoB8Xrh5XABpslkvA== X-Received: by 2002:a05:6512:a819:20b0:5c3:182f:bad2 with SMTP id 2adb3069b0e04-5c3182fbc8fmr5664836e87.0.1796147037399; Tue, 01 Dec 2026 09:43:57 -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 2adb3069b0e04-5c1bd0419c2sm8962364e87.52.2026.12.01.09.43.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2026 09:43:56 -0800 (PST) Message-ID: <58ddcba6-d1be-4c4c-987d-eb7170dc716b@gmail.com> Date: Tue, 1 Dec 2026 19:43:55 +0200 X-Mailing-List: llvm@lists.linux.dev 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: Ian Rogers , Guenter Roeck 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> 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 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(). 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! ~~