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=1796389436; b=lmlBgW51jHtF9A0QaKHZ2ixqH7XxFiAFeKW1gBj2M04Uc0eCNnJrT4DV4RvVqxPPMP8d GGqIU1VexfHIKS3p+3VgklbVkVd2COPOgCy2qz0Jt4IWv+IBZZH/IUsN2gjLfME1Gh10x CzZ97W1tWrbd/E9SYxQGFTF/LEw3CyGgicqe9eh6adlQOs0YTvnHOy3Lsgibe2F7bB8jP vXVHT31L3ltRfzZx65suoeFtn0ZUKyLxAnSkcrcrY7/0JYbdgdP+YTtVWGSDYm3TwMkCA gpvzGcm5Ki1JUrNfHKVAyTBOAy7DfpPbObuCDmxBUVVtNgXQI9yORy3UHLBJ1ecck8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389436; 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=SlNsDIPEAp1mf76sXbPBdf1A4F1haTRwXra9RrQOmbk=; b=VQtzPd+qwdzXPmz6ALEFkGTLYRrw1ml3L3c63//7NH6AXKSpsuYNsENohXDQuOLlXID8 aGJPbOwd+cGlduNQHB9N7cX9QVJ+WhOxpk4gHOKISO+eLOnAtlQt4uiMk5zCgnsetQPse CEw5bipLFgYjvLjMJnjfJ7L1/XauMLF+6DYkIjHsEfPncUkS77s6IiK+J3VyrJjQ6WvqC 5QvFxqlH4arJeu/SpwJ/oLYLfYGYj9gEz/ZkVQJ/cL5TGNhaFmyM23i5SlZY7+R46yQRh rVA1PMrfZ/P9qnoC0mpI1oxnRv0PTIhQPmofkqaXtWdd7CVAD02xpA4a07REauCiOUw== 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=OlzloV67; 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 C1796606A336; Fri, 4 Dec 2026 13:03: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=OlzloV67 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E4B21F00937; Fri, 4 Dec 2026 13:03:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389436; bh=SlNsDIPEAp1mf76sXbPBdf1A4F1haTRwXra9RrQOmbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OlzloV67Mm+McJRuZMVGDp8+eAYSoQ9RfykPxVdiilJotOE/U2itHCJ7bYBaYEXq4 CIobnAH7PrqlJcw/6NZ9lMup1MCO49lP4RDP+nYej3dOR4L3kM14xEN041yEzSYUtp Bp9FWVER5pfcPbT1idHWTOrt4qd8ap6+d0460x5w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhao Feng , Guenter Roeck Subject: [PATCH 6.1 0992/1059] watchdog: npcm: fix sleeping clock call in restart handler Date: Fri, 4 Dec 2026 19:08:43 +0900 Message-ID: <20261204100709.692704998@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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);