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=1796361735; b=Fo9S2lAel/ho48rS14VkUbcH3rg+46w8qraENOcyLD0nOoKhKRfTEocWUCOb5LMwGhat EbRseUTh4oIyyx8iMU/XvuWIs6p8/JMZVwdfnsd/M6nSs5g8NRLO68sUm9O835ttrMJB5 2qzN9SNWkQDkbvjT76PYOhZ5OTyPsW/L2lCsqUG7D68BP2gxvcBqqHh2pp6Vzkn0dg6mo r/zJNv4K9wL/LYZddVghql/ZmQAQh1/LUew7/qpxj8CBZ4L2/H/69n3DUnpyn2gcW0nY2 7KeDbnZkoCCy7XhMPJEPLg/v0R5h2IFvjTCCUC2ObbNAZqDCKmGEQJ60BnHgUIOxHEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796361735; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=JJGarhHZTF5zMuFGl2GN7g6xi+sgWq8DlTn7V473Fk8=; b=NTO503F1/40YrmAxhrpwdtzDeEheRyZJolrOqEIRgvH4VEw88WoG3eNMc5yv7HAI73f7 /K91bKg2bOMAVHlOa940lUMcQgVJ7ZHqGTYi7oODfazqW1KHmBKmKXCT/SxxnjYOyR2Gh bxMUOtyjVykTOWnb5HEzg1Gz2UMOwkh3Y5Tu0WJhbV8kMEuAd1Es8SJuI/Y4ZifFcoD4L 1T6SN5T6IsVYUzvyHuqb7i5PQDJe2ogcmMoQzQwgDuDjavvGiVqYMO16kiiR/wH9NvEVF iT9Pnywr6B2AuDXM0RhjbRRvnaottIuv3axugRemdO0kxAu+e+Zu9LBhXLRVeuYUW/A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="nWZVG6/9"; 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 BE12B606A322 for ; Fri, 4 Dec 2026 05:22:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nWZVG6/9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADF071F00897; Fri, 4 Dec 2026 05:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796361735; bh=JJGarhHZTF5zMuFGl2GN7g6xi+sgWq8DlTn7V473Fk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nWZVG6/9U8D518whfnYc7oKqUtA6cGDOo5PcxZyNMkL1uIahnB9YKgcWHTO3ougvS npK/dEEZ6TxpTGqsazwl/6Hd8/EFQ6QgCjG1lXsAa0ASWpx8ihq2T4IZwd2H3Cp82I 6eEGLxaSmfiM3nh596COEAwdxBBXI/Ioz/uLsYDDekSoy3dDzN1++6k1dC5y/mIRsl fNR+B13LhF2zp+mUlR99kyVT2cmZ5rt2P7ka5W2PtOUNOzh/KwF/KYqhKYj54X5siG ap+YnjCGvjutWGxfUrNWioetPPlIDWbEYGMx1aZ4BOO4N/3fYuCjk09V6D8ka1vlui BaaGSOHjhfjsQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Stanley Jhu , Bart Van Assche , Peter Wang , "Martin K. Petersen (Oracle)" , Sasha Levin Subject: [PATCH 6.1.y] scsi: ufs: core: Introduce ufshcd_rpm_resume_and_get() helper Date: Fri, 4 Dec 2026 00:22:13 -0500 Message-ID: <20261204052155.2761620-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120214-pasty-eggplant-a00a@gregkh> References: <2026120214-pasty-eggplant-a00a@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Stanley Jhu [ Upstream commit cbab12e5b4a7f49d5add4301de275351269cd431 ] ufshcd_clkscale_enable_store() and ufshcd_auto_hibern8_update() resume the UFS device W-LUN with ufshcd_rpm_get_sync() and ignore its return value. For clkscale_enable: 1. The W-LUN is runtime suspended and clock scaling is disabled. 2. User space writes 1 to clkscale_enable. 3. ufshcd_clkscale_enable_store() calls ufshcd_rpm_get_sync(). 4. The W-LUN runtime resume fails and the W-LUN stays suspended. 5. ufshcd_rpm_get_sync() returns a negative errno, which is ignored. 6. ufshcd_clkscale_enable_store() enables clock scaling and resumes devfreq while the W-LUN is still suspended. For auto_hibern8: 1. The W-LUN starts a runtime suspend. 2. User space writes a new value to auto_hibern8. 3. ufshcd_auto_hibern8_update() sees that the W-LUN is not yet suspended and calls ufshcd_rpm_get_sync(). 4. ufshcd_rpm_get_sync() waits for the runtime suspend to finish and then runs the W-LUN runtime resume. 5. The W-LUN runtime resume fails and the W-LUN stays suspended. 6. ufshcd_rpm_get_sync() returns a negative errno, which is ignored. 7. ufshcd_auto_hibern8_update() writes REG_AUTO_HIBERNATE_IDLE_TIMER while the W-LUN is still suspended. Add ufshcd_rpm_resume_and_get() wrapping pm_runtime_resume_and_get() so failed resumes drop the usage reference automatically, and return early in ufshcd_clkscale_enable_store() and ufshcd_auto_hibern8_update() when it fails. Fixes: b294ff3e3449 ("scsi: ufs: core: Enable power management for wlun") Cc: stable@vger.kernel.org Signed-off-by: Stanley Jhu Reviewed-by: Bart Van Assche Reviewed-by: Peter Wang Link: https://patch.msgid.link/20261029040003.2100003-3-stanleyjhu@google.com Signed-off-by: Martin K. Petersen (Oracle) [ sashal: Replaced the ignored ufshcd_rpm_get_sync() calls with ufshcd_rpm_resume_and_get(), using the older ufshcd_hold(hba, false) signature and a hand-edited older ufshcd_auto_hibern8_update(), with the helper placed after ufshcd_rpm_get_sync(). ] Signed-off-by: Sasha Levin --- drivers/ufs/core/ufshcd-priv.h | 5 +++++ drivers/ufs/core/ufshcd.c | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index f68ca33f6ac78..8802f16487413 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -267,6 +267,11 @@ static inline int ufshcd_rpm_get_sync(struct ufs_hba *hba) return pm_runtime_get_sync(&hba->ufs_device_wlun->sdev_gendev); } +static inline int ufshcd_rpm_resume_and_get(struct ufs_hba *hba) +{ + return pm_runtime_resume_and_get(&hba->ufs_device_wlun->sdev_gendev); +} + static inline int ufshcd_rpm_put_sync(struct ufs_hba *hba) { return pm_runtime_put_sync(&hba->ufs_device_wlun->sdev_gendev); diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 24d1321a9b519..509f9f4d96b5a 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1574,7 +1574,9 @@ static ssize_t ufshcd_clkscale_enable_store(struct device *dev, if (value == hba->clk_scaling.is_enabled) goto out; - ufshcd_rpm_get_sync(hba); + err = ufshcd_rpm_resume_and_get(hba); + if (err) + goto out; ufshcd_hold(hba, false); hba->clk_scaling.is_enabled = value; @@ -4282,7 +4284,8 @@ void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) if (update && !pm_runtime_suspended(&hba->ufs_device_wlun->sdev_gendev)) { - ufshcd_rpm_get_sync(hba); + if (ufshcd_rpm_resume_and_get(hba)) + return; ufshcd_hold(hba, false); ufshcd_auto_hibern8_enable(hba); ufshcd_release(hba); -- 2.53.0