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=1796384078; b=dHj3wIs+GtT4E+Re8nV7JVGCE/yypYd6QLgmZ7/1E9kpJhrOwQvlUNLPJqithOtl37DP ngR01FSoOs9heLSpEEMI3E7v4fufIrqIFUN71Q0LpBAlS6aZnIMz8Y1dceuCgZGU65nA0 Ofp2y3r3doFzliEVCAaFYZuf/fepytEsShJjWyeJiDZm+01cAG1U1/kGw3DIiWv63iNBs Vid9SQP77rhmT7yNuLLIr/k+Q3LTToz/jfF+R4BbcWjdtpyXfHZTPNPIFaj4Q25LvbzzI gxahdZVhlM3F03YET7zHWlLJv80w+2p5Xhd4qUUPCvZ05WOGjY7/HMP3Pfkuw1aG9Cw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384078; 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=zGRJRNaF9lR9cVfMS2azeOwn7YYtI7e8XjGbuPLB+oQ=; b=MdmRr6WLU4+fJhPMmmFy/aWnsfDI2dumY5OLVwdxyyH3hxDk+NLFEGcH9enyfcCaoFI5 CXYmoJ0snXt0NoJfGR3Yvsgv9n0odTAGYWTvQzJqWD1ZblZ4m1+a0tqy021eaBRGThh9F hZ6IDjX9kmSqxSSyiRCA+SauusXzWZkwBJHEUqbO64yLR/4K5nCfYPKHUrM0GLmgfTlWJ ppeD8UP422bfH3WPmIFtVhYj1Sgg93j9ysr3MixgdSD9ut/o2G8Aux05ktZ6Nw04F3rEB kTG8AhfCkB92sxDnRIBrvTw23LxJ/mWYcilkVwAjnunMmkqxsgK6RhR2zXG+M+Z3zJw== 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=Uqob9sWw; 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 1DF2E606A322; Fri, 4 Dec 2026 11:34:38 +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=Uqob9sWw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EB091F000CE; Fri, 4 Dec 2026 11:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384078; bh=zGRJRNaF9lR9cVfMS2azeOwn7YYtI7e8XjGbuPLB+oQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Uqob9sWw5LGSIUH+D8IpgFzQ2uQBd8gnXLC/f7j/Ay5J4rdXJ7FHN3cPGIkl0og/k jxgy8c+Vc8cQH/wFmA5qLWN2p/LeM6cS+0l6Cng2FylbjrdXC+D1JmqySGNclin6Q6 cODa/Q8tPmIAqLr3QYsxBOVgabLYubVFV0DbdEfk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhao Feng , Guenter Roeck Subject: [PATCH 6.12 459/555] watchdog: npcm: fix sleeping clock call in restart handler Date: Fri, 4 Dec 2026 19:08:22 +0900 Message-ID: <20261204100626.880300047@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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 6.12-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 @@ -98,7 +98,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); @@ -111,7 +111,7 @@ static int npcm_wdt_stop(struct watchdog writel(0, wdt->reg); - clk_disable_unprepare(wdt->clk); + clk_disable(wdt->clk); return 0; } @@ -160,8 +160,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); @@ -207,7 +211,12 @@ static int npcm_wdt_probe(struct platfor if (IS_ERR(wdt->reg)) return PTR_ERR(wdt->reg); - 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);