From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147041; b=tcOfp5NvGfAg0IeTKZxtBja3moDfqb9YAyCT22hN3nFwcmR5pHFKi8/xp6CRS4u9k65b YNxpzEk+/ocZa1cllzBZt4Ch+T8/66fgbirjf4QmQ7sl/wsTRYRxucDMfkaeWWMCA9VY9 rBXwwPjYKnQSlmuv9X4Pl1X3iVYLZYowhvDr++VBuamxtcXvJ4RPlz+Sp8xyOHOScyLDb vpIROkNoIHwTe+zv9zB5OnFbqCwObKyFYUGspQ/G59OJ296xljSd89HwnHNtXGi14cc8R cnJhmsSEkJ2EBd+Aoun/x5qETIrIq1ycRtYxaKni+QIwbqVY+UIDoRFS4AkMPivtxbQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147041; 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=zsLeKiNBmaxeTVkMjIId6OQpp/ZuPAxMdGA6J9C7RWy7C3MfPSkxYpFHbyEWxk+/UPEj mXirhnRT/0HfeUgDtkcJA9fMkurvbVeLH8CrMWEyt4ta+XoX8O22bxtHc88aqQupdgjJo 8YzNBAwuACaJ/0BxbLtIs+99MFwGnrZRdugE4EA+uh6+YJfUYD4ctnEZm89UNmNTxtaPe 8NdcKcdBu/KFwwap9B/gz4EdeDwzbXoBXNqfVHjqhp+IQmF8oE55CkQLqn3ATv8DgN2mo FdBaqBrsD+kr4JEc/raG75azotjgn8DblK0gXlmSroLZ3kthlLGgZ3bvzNmSrtlkecg== 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=NzGx3W2J; arc=none smtp.remote-ip=209.85.167.45 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 6C5C1606A68F for ; Tue, 1 Dec 2026 17:43:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6C5C1606A68F 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=NzGx3W2J Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5be3d5927ceso1616633e87.3 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=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=F2PJFf4WfqXxB1k0B05Txy6f1J8jTGdt+SmEEMsG0AY=; b=NzGx3W2JtARQlv5rz5YG93xNaW0DTVsyicUBci2tPfZaM3xey7+qqdeoD1h2ciE31S sgraMAlgkfhFxUaBlV5go283WAxpPHFlcGp3W+5IGj5zpeeDuuDSLzuMPKlxJkWQQbdv aZRL5LU7ORhuP02YbsSskKZc+D0QWC9QrK5nW6wS56GGrKOTviLIQizR89bwP96caDD5 Qws7YshYEnlDem3BDEkiHrTI204lj2e879V+jff+kkGRvVt9/CBCkit/EleqX3aHeSXZ mfJFYoNwqKVLg9uMXj89owHNm+iEHLkSQKHAszc0FqKDwwqTO9mACYB9B7IjTX/0CM8P VdmA== 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=geG+hjTOqToc4dAet+2A4z32pJfY5BSXlwojLgXhfWtflLPXsd0sJdrW+PR8F7G3iA 46dII0tlGXE4JDAb6ElmKU0RRJweMrzmSMfVI9ozZTJdLnfD1Az6sqMmOxNdRzCBGiQ6 Z8//kZ0VQxoYfkdYEoulJ274hfKjtzbh53lPi4b3oaYg6kIlYV6Wsacnu/VfHLoPofRE mZCXlma2lYm56LI7qiF/IqmwrvN/td9VQSMqLytso1BgyjhrD24J7U8bmjLU/iDdEPnb UQ4VYkv7+h7KRAZreXL+Yn9jS9qxJ2TST8uJb8uoF5fU4Dx48WmPyQdBXwXsx8RTLcKH nlNg== X-Forwarded-Encrypted: i=1; AL+hErEEW/PuOhSWWxpMzZXSfVex8rOc7aR5SP47OeACXbKsG7UFAwWQMKziH9lssTUCRlQbzcMdsZdxxd2dFrCpfg==@vger.kernel.org X-Gm-Message-State: APuU4Z/nJAGY7SBZEcERlh/psvqCr2JQXX27BTjK0UHYZDFkvx9u6Wi7 7en0Fdl3KFWc5ok2gdQwxga2XvLgj4JZVje9iMRVv+haX+A7/uwatgyF X-Gm-Gg: AZFdTZdzO2HBrD6mEryduHbXQ/bFfRvD9+jJhajeJ2Zkqb5AJm9BgMyZe5dvLMhb5n6 LK6EuG22Rlun9nCl7ISS5+bT2NC0nmQJa4f78UfDkccY3cu8Mo9iw3oBC+W6aFB+EIFe4tou2Yr Fe8CTEt3oTiiZD3ce9bEi4jE0K0WYzP76YgOdwdcwZDCtE7hXok+BWbUPyUCY256wGVhomLRZ77 KfoqnMMxY/Bd0tkp+3+ivopfxL9sz8Z62mllnLTHiwEABT+iHENoZdq7D2CNez6QTOfGgxyzUPb QQtaAt2hmIcZKkIeV0xsaffk1oAtKQZKv4Zyq7VRHrBY5c6LjA+BSRY1KZGzqyvjBVpQfdsyFgn bpGOxtGUXJumIPWvK77GXKhX7n9I8HnH8uVkhb2vDCUhxTGbVrJi2qezGN3LqP2cS3MBU+g2/sX jNbWSVjm0uN4IRSbiqiwlxT9k5dEh3F3BcKkykNDVqQ2U4eHafPEPK6ToeDc8SERY9VZYR1GZ2b fAKIhsydvmqmJu3l1/yycbF4Tngzy/6MBQTpWocbz3cB9s699/8wkuUiKO+RV1xFNdEb9vNgxTA 97cP1isc+ahrZc/pURFA1dIBRE7OO7YDI56U0sBVciviSEmzKCfVNaMRvI0A34AZ0t8iYdVBoOG hkkUdodMekzzJsw/5hhO9SvUt9AsBLA== 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: 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: 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! ~~