From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796193543; b=aZhYtdU9qqJ38egR9EsrrJjXn52INDOpOWEjdfk+zyz/PDu5P19olyLDxWNKiOO4ZaYr gOwxziQMjhCLTmBptJSOjw+lmQ36ETLnPNUStuMoX72qUr7eELMFXTkbe0bfA3TAUgC3p VP3h1BlADI/h7twsOmv6RIhA/rUuVZn5fpwt7HRQLWLy9ZpVCzfNBph7hYN1DK01p4DXd VGo0lyJt3I//u9o9L10aKWCEOurF5be2rj9QPgHQdCnUXAjTjqZeup/PT143wgtdpyQvw NQ0s0AFF6Of0nleoW2qV5VC8XsPg4wRgrnwI0iWCGrT0WELd+v31QJtV/NDTso4yt6g== 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=0ycA6ClauJMzzlTCl/kuVdaZzM5P6tnWfInE/ihQJiDmg0R8sjsD97IxiB58httQTFkp wCfMtaYjU+acmIgSFlInxjClg5QLQOVbzFVaO7skvqAHNOUzFymmVXod6lrIxBPaujfbu 0e1mQDeaaB4as8jcK/TGQDeeuaIaA7vcuK546IwQmNjcFiAt8MB8lZ8KhhjwbreaaVVvW URMMaikEqQowReqp9U51S156Vq0qdwIjbEBv8Gcma7RcPlbQz8jkTA2QOaPcrUsKf3KOO iiJnQgt5f9qbGKiDtWDYUPWddeMUrfB10sCoSsqbcvBiF9OEvToo18OTILf6y4G5+OA== 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="fYPS/2dI"; arc=none smtp.remote-ip=209.85.167.50 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 39BC8606A323 for ; Wed, 2 Dec 2026 06:39:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 39BC8606A323 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=fYPS/2dI Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5bccecba199so12221709e87.1 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=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=X4+Y4YVlDgU/iQIwgDcTbxa6Mdk0fgw6SkI9SFfRT+Q=; b=fYPS/2dIUNkyrk80XIghwINj+8OyA8gMwWxGhd5ZEdrN06VIow/3tCRVhUNltWVVTo FmmPl0ib2tOIEnxX2FJBznCtvteBSsJs6t4oFxBs5GMdWl6+hEhn3EmiTH0m6IWz0Vr/ n8EQ32U43v+D1KDxAEVY75SAICs4ONj65S98ev9M+wB5YZPk5um5S3bjizYIHp8c2Faw g3dmLPFWXilIDsoS+NXmrvKmHeMvu3epXkdy8LB2Xu+aqTfjz1gOf8khqLhYSuP6a/uj P9Cl2FQ4wFwiQwfrzy4u6DVDfPNbarDau0TQr8Rib0omn+BEPb3WdQWsWcEiDOmvGWmx PfTg== 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=kfm5l0nJsXpM1jFC9EpW/ZkkRHJuKpD4e/xFB4J7l0o7mkC3xRAWdMfOdsHM4PDcBt AIv2tdpy08XYHAQ6aWQtLHz2g6WoDDnO4QZ750SiGa/yfWtYlulsbBS6IJIGmhDoMGD5 zjTYBaAo1oCLYD13mpMWv28OA31KbETa7Ew5MDid0zN3xcCJ1lsJYisqG5kBX9phMMqf jWU/Qus8QNrCl46U9S3EUhtaMKKVQLkJ+OWGm8VPAbsK5Q0RG9ceGfRiFjXHD3aHiLGK bnj4W87SB8g1o2d5s+VM5tt97B6xGfs33g+RjE8kBAT4DcwKKdlt921UbS+qA9M3MGer 54kA== X-Forwarded-Encrypted: i=1; AL+hErFNkE0Ce2ro2IN/DFmyrft6sb5GvDxYOy/msW7RhjZtMi675u0qsFVhHORYllLOBd6XSJ8U@lists.linux.dev X-Gm-Message-State: APuU4Z8z4JwfoGQwRCcrUOp1zD0WE3sRaFGnbfgiX6V6pXE27YytSzrC W9vL3PlmIhEe9/us6SeYKB7qR4vQd/i4mJzhDbJRAW5X/FezcV5WJuzz X-Gm-Gg: AZFdTZeznk3FTCP0dgPlldkqwLD0jAUL1mIDEUvuVj/eFwsbga7SA5Xp/kf+tFr2WzF Bbe8GUUxGJzvqy8VEy+vPAvcLVz5YOnRenv7EM1PGIOogd9l43BD8eShsqDs6qKek/s0BV44HIA LOj3n+8A2lX09J1zeXDWo9lMBr7mSB03sAONbApCCV+ZScMZ4Mza68vHqUjRG7kF000boPf5+1J Gon54YDokC/k/yN/5q17Sfyfah3WJ5R+blyi0FwYknJjzjE8sYmmKNk2X/SdRznOvcWD71UhAf8 pem2GeKFaN1V2W90HOgnXI8D3uKeBbVxJYHRtw8eXZwLOW+BaOZ6SVvi8UPCwpfeV+xP46Qhm31 bnyxWZdmbO9UjtxapErTYX9tJALpj7pCz2Kz20sUqLrcEbMIngS39WAseaKKHcHwa8JddtiniMo O8g3oLWlEtni1l7hqRNMeKpgjBuXMr4Zb3WIOUbP/5GlrF0Yb3w+wQ7tV5jAcuiWAMoTuIaXkX4 JI4Gfa+TeIbWEvQEbzadwkODRojKwQzxeMc4Qn6f+0mZYgWjqtWi8haRvTUDrO2OKXa2HCvJXU2 Zve0lYyO3vxApzuw83WOlYbQ0nJZld3i9qKEVsEMpsKr24hNi4obbY+DkwuUVgwZfOpzprLGolU PCQZ8HqPK 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: 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: 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! ~~