From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381217; b=p+z4hh9DFQQ/WIqMrmdIR3N/BmUEWkzY0ArtWse12P6i1a0uFoRwCSeZ2ZnItlbgyJJQ 997MVdT5xj1vfPZbBEEPRWQi56XLcHAzXWKvFj3sBwzlrtYCRfQPZiN3KXbYZ98jQlgTJ Am5wPtn6JL3R+ux4FcZmIvzZSf0grq8dIBjhbnxIbQCE+Yk/M89ux4lXJZVpiaeUq4Ead RXP9zV7jr39l8S0I/n1IngL9f5JHA4N70M6NrK0GvOYdODASWwakRlyDYcLRY1esSRMDl Y64c1zPlJt7/XRVCqc+HqNqOSUWvWIgXKjUd35ykYACXTroxIU6iN2rI8xxaaXAjDvQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381217; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=hIC6AMgKZucwKKTTrUgcHGS/zYxl3UxapWfHEqDSm6s=; b=NYrbw3TH6Xrb5ZKTPCEivOnp/YsZqvU910sc81SGroivA6gGr+MVMUITTaM35HfuIzok jmV5Jt709S/QJObcUKid1zT7BKVd85mzdnWM+KmViL/RFipfaHkbUSaHu1KOcV5WJSmJa bLXvXZGbvDSRB+AqiedO4htNit7AlDaX34W5x6hk1NrqnRuG2NORfboTANq89OuppE91i gZYPWUIt0UKRzlzB3f6u/CpRIQdgJSPyVkIL4SFXrAIz0MSO4TSK5LiK4jSpJsy4Njw4v 2C64CzUbW86KlpAvZPOZXwjNsm5zpb0p99iVl+TKXMXPN1QAoQZyTSq58j4vb1YgOxA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=T38nhNRp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EABD7606A322; Fri, 4 Dec 2026 10:46:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=T38nhNRp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84B871F000C2; Fri, 4 Dec 2026 10:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381216; bh=hIC6AMgKZucwKKTTrUgcHGS/zYxl3UxapWfHEqDSm6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T38nhNRpHB1/gGasfLNxnuvSiCYEfzrDX6r70GiGEzhPfMfv3a7O2b9VYc37ndTeE Kqz8veilfDvEnas3REIpn8XHqtRwwoF6/kSaLCF9YS3aIEEnk68dwiTXFzOI80O94n LkJ/Ih8xqjoT0GWjmhX+nuJ/BesRyLDK+4fyTOGg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhao Feng , Guenter Roeck Subject: [PATCH 7.3 608/742] watchdog: npcm: fix sleeping clock call in restart handler Date: Fri, 4 Dec 2026 19:07:52 +0900 Message-ID: <20261204100651.266754448@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhao Feng commit 4e83ea5b22193fd0db8bcee5682935f1d528705e upstream. The watchdog .restart callback runs in atomic context: it is invoked from the restart handler chain via atomic_notifier_call_chain(), under an RCU read-side critical section, on every reboot or restart. Since commit af084fdccfaf ("watchdog: npcm: Enable clock if provided"), npcm_wdt_restart() calls clk_prepare_enable(), and clk_prepare() takes a mutex unconditionally, so kernels built with CONFIG_DEBUG_ATOMIC_SLEEP=y report BUG: sleeping function called from invalid context on every reboot. Worse, a panic-time restart can block on prepare_lock and never issue the reset at all. Get the clock with devm_clk_get_optional_prepared() at probe time and keep it prepared for the lifetime of the driver, so the restart handler only needs clk_enable(), which is safe in atomic context. With the clock permanently prepared, npcm_wdt_start() and npcm_wdt_stop() are simplified to clk_enable()/clk_disable() as well. Fixes: af084fdccfaf ("watchdog: npcm: Enable clock if provided") Cc: stable@vger.kernel.org Signed-off-by: Zhao Feng Link: https://patch.msgid.link/20261111083236.248-1-zhaofeng2@cmss.chinamobile.com Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/watchdog/npcm_wdt.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) --- a/drivers/watchdog/npcm_wdt.c +++ b/drivers/watchdog/npcm_wdt.c @@ -180,7 +180,7 @@ static int npcm_wdt_start(struct watchdo { struct npcm_wdt *wdt = to_npcm_wdt(wdd); - clk_prepare_enable(wdt->clk); + clk_enable(wdt->clk); __npcm_wdt_start(wdd); @@ -193,7 +193,7 @@ static int npcm_wdt_stop(struct watchdog writel(0, wdt->reg); - clk_disable_unprepare(wdt->clk); + clk_disable(wdt->clk); return 0; } @@ -242,8 +242,12 @@ static int npcm_wdt_restart(struct watch { struct npcm_wdt *wdt = to_npcm_wdt(wdd); - /* For reset, we start the WDT clock and leave it running. */ - clk_prepare_enable(wdt->clk); + /* + * For reset, we start the WDT clock and leave it running. + * The clock was prepared at probe time; only clk_enable() is + * safe in this atomic (restart notifier) context. + */ + clk_enable(wdt->clk); writel(NPCM_WTR | NPCM_WTRE | NPCM_WTE, wdt->reg); udelay(1000); @@ -417,7 +421,12 @@ static int npcm_wdt_probe(struct platfor start = res->start; - wdt->clk = devm_clk_get_optional(&pdev->dev, NULL); + /* + * Keep the clock prepared for the lifetime of the driver: + * npcm_wdt_restart() runs in atomic context and may only call + * clk_enable(). + */ + wdt->clk = devm_clk_get_optional_prepared(&pdev->dev, NULL); if (IS_ERR(wdt->clk)) return PTR_ERR(wdt->clk);