From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-106111.protonmail.ch (mail-106111.protonmail.ch [79.135.106.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E80C4358D37 for ; Fri, 5 Jun 2026 17:19:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780679997; cv=none; b=Iq9s9spxaMbC3P7DRkA2x8WEauM9jqYsBLIclhu4O8ocHEIyvATVEfLNODG/TZuNhkWqsq5FksD/RwWnvkywPH49ZYT94ZO714svkCo3U4uR8Vh6mmsyPW1xzte3uEbM9B7RtEiBqX2fxOaxLnELR+MsQit3x2w6HCFLXPLG/AQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780679997; c=relaxed/simple; bh=okmxrgBCvufTcX32FIBoSLwcDGUzqtcDdCzFnkaOA7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BylaHcZ6I8KGb54aozBn8yFMCrQ6OxdT/qO/Qe6u+yGPLG4sY/6q9A9TBb7zF/asXs9ZW5PJFQFVAy2qgUC0QH5ULyMtN/iFI4oPEkiEjgrsmP9KXtEYaTwxHGeLv9earRHA5D35f+vzR5QpFmW6U1hJzPZKo1Miyp86mof75cc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=theesfeld.net; spf=fail smtp.mailfrom=theesfeld.net; dkim=fail (0-bit key) header.d=theesfeld.net header.i=@theesfeld.net header.b=ui4XRlhA reason="key not found in DNS"; arc=none smtp.client-ip=79.135.106.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=theesfeld.net Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=theesfeld.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=theesfeld.net header.i=@theesfeld.net header.b="ui4XRlhA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=theesfeld.net; s=protonmail2; t=1780679989; x=1780939189; bh=s2Tq9L+mxJV1LF+CSfNq0nEeRrlDQozObfED+HQhBNU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=ui4XRlhALxtb0GLmeJsQCT8vh2XKH7OwDJNvDI1E4KW0+vKaRzOyTA/Q9C16c+k+R gj0WoSZ1eEbO2qx0fvzDyTtGCJQaSP4PMoLX0GsJnhNO8gnCsaIJBhq9cpHA117L0B +6DGhSB/D1nEhomHNur2z0174icqn1IurMeV26RMRmv2/udjXt0yY29Qjj3wpBnk+b YvoB45pI43v/tWcteMKyF1SU497D8u+CgMW6B/WHgjWjBwpvIOC1DPNdDg4hWDP80r Ng/wh5daqb2nzFdnwgpAYonRAFAoX80+V8TEufA6hBGYfHaaof4QKAP3bPr95NUGNT mx1HRWjgZMRBA== X-Pm-Submission-Id: 4gX7Tt4DgYz1DDXm From: William Theesfeld To: Xingyu Wu Cc: Ziv Xu , Wim Van Sebroeck , Guenter Roeck , linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/6] watchdog: starfive: balance PM refcount when start operation fails Date: Fri, 5 Jun 2026 13:19:37 -0400 Message-ID: <3a2ba59a0ed3e5ee121a49e04c5bed0c452af238.1780666366.git.william@theesfeld.net> X-Mailer: git-send-email 2.54.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit After pm_runtime_resume_and_get() succeeds in starfive_wdt_pm_start(), the runtime PM usage counter is incremented. If starfive_wdt_start() subsequently fails, the function returns the error without releasing that reference, leaking the usage counter. Call pm_runtime_put_sync() on the start failure path so the counter is balanced. This also folds in the v1 conversion of pm_runtime_get_sync() to pm_runtime_resume_and_get(), which was the original purpose of this patch; both fixes together close the refcount-leak window in this function as flagged by the maintainer on the v1 thread. Signed-off-by: William Theesfeld --- drivers/watchdog/starfive-wdt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/starfive-wdt.c b/drivers/watchdog/starfive-wdt.c index af55adc4a..ed8c5711a 100644 --- a/drivers/watchdog/starfive-wdt.c +++ b/drivers/watchdog/starfive-wdt.c @@ -371,12 +371,16 @@ static void starfive_wdt_stop(struct starfive_wdt *wdt) static int starfive_wdt_pm_start(struct watchdog_device *wdd) { struct starfive_wdt *wdt = watchdog_get_drvdata(wdd); - int ret = pm_runtime_get_sync(wdd->parent); + int ret = pm_runtime_resume_and_get(wdd->parent); if (ret < 0) return ret; - return starfive_wdt_start(wdt); + ret = starfive_wdt_start(wdt); + if (ret) + pm_runtime_put_sync(wdd->parent); + + return ret; } static int starfive_wdt_pm_stop(struct watchdog_device *wdd) -- 2.54.0