Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
To: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com>,
	Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konradybcio@kernel.org>,
	cros-qcom-dts-watchers@chromium.org
Cc: linux-arm-msm@vger.kernel.org, linux-spi@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/7] spi: qcom-qspi: Fix incomplete error handling in runtime PM
Date: Wed, 15 Apr 2026 11:46:13 +0200	[thread overview]
Message-ID: <fe30cca9-c348-4ab2-b190-33016242aa64@oss.qualcomm.com> (raw)
In-Reply-To: <20260414-spi-nor-v2-2-bcca40de4b5f@oss.qualcomm.com>

On 4/14/26 7:08 PM, Viken Dadhaniya wrote:
> The runtime PM functions had incomplete error handling that could leave the
> system in an inconsistent state. If any operation failed midway through
> suspend or resume, some resources would be left in the wrong state while
> others were already changed, leading to potential clock/power imbalances.
> 
> Fix by adding proper error checking for all operations and using goto-based
> cleanup to ensure all successfully acquired resources are properly released
> on any error.
> 
> Signed-off-by: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com>
> ---
>  drivers/spi/spi-qcom-qspi.c | 40 +++++++++++++++++++++++++++++++++-------
>  1 file changed, 33 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/spi/spi-qcom-qspi.c b/drivers/spi/spi-qcom-qspi.c
> index 7e39038160e0..38af859713a7 100644
> --- a/drivers/spi/spi-qcom-qspi.c
> +++ b/drivers/spi/spi-qcom-qspi.c
> @@ -819,19 +819,31 @@ static int __maybe_unused qcom_qspi_runtime_suspend(struct device *dev)
>  	int ret;
>  
>  	/* Drop the performance state vote */
> -	dev_pm_opp_set_rate(dev, 0);
> +	ret = dev_pm_opp_set_rate(dev, 0);
> +	if (ret)
> +		return ret;
> +
>  	clk_bulk_disable_unprepare(QSPI_NUM_CLKS, ctrl->clks);

You first need to disable the clocks and only then potentially reduce the
performance state, otherwise there's a brief period of brownout risk

[...]

>  static int __maybe_unused qcom_qspi_runtime_resume(struct device *dev)
> @@ -840,20 +852,34 @@ static int __maybe_unused qcom_qspi_runtime_resume(struct device *dev)
>  	struct qcom_qspi *ctrl = spi_controller_get_devdata(host);
>  	int ret;
>  
> -	pinctrl_pm_select_default_state(dev);
> +	ret = pinctrl_pm_select_default_state(dev);
> +	if (ret)
> +		return ret;
>  
>  	ret = icc_enable(ctrl->icc_path_cpu_to_qspi);
>  	if (ret) {
>  		dev_err_ratelimited(ctrl->dev, "%s: ICC enable failed for cpu: %d\n",
>  			__func__, ret);
> -		return ret;
> +		goto err_select_sleep_state;
>  	}
>  
>  	ret = clk_bulk_prepare_enable(QSPI_NUM_CLKS, ctrl->clks);
>  	if (ret)
> -		return ret;
> +		goto err_disable_icc;
>  
> -	return dev_pm_opp_set_rate(dev, ctrl->last_speed * 4);
> +	ret = dev_pm_opp_set_rate(dev, ctrl->last_speed * 4);
> +	if (ret)
> +		goto err_disable_clk;

similarly here, the OPP state is only altered after the clocks are
running (potentially at a high speed because the rate is cached)

Konrad

  parent reply	other threads:[~2026-04-15  9:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-14 17:08 [PATCH v2 0/7] Add QSPI support for QCS615 and improve interconnect handling Viken Dadhaniya
2026-04-14 17:08 ` [PATCH v2 1/7] dt-bindings: spi: qcom,spi-qcom-qspi: Add qcom,qcs615-qspi compatible Viken Dadhaniya
2026-04-15  7:56   ` Krzysztof Kozlowski
2026-04-14 17:08 ` [PATCH v2 2/7] spi: qcom-qspi: Fix incomplete error handling in runtime PM Viken Dadhaniya
2026-04-14 17:46   ` Dmitry Baryshkov
2026-04-15  9:46   ` Konrad Dybcio [this message]
2026-04-14 17:08 ` [PATCH v2 3/7] spi: qcom-qspi: Add interconnect support for memory path Viken Dadhaniya
2026-04-14 17:47   ` Dmitry Baryshkov
2026-04-14 17:08 ` [PATCH v2 4/7] arm64: dts: qcom: talos: Add QSPI support Viken Dadhaniya
2026-04-14 17:47   ` Dmitry Baryshkov
2026-04-15  9:49   ` Konrad Dybcio
2026-04-14 17:08 ` [PATCH v2 5/7] arm64: dts: qcom: qcs615-ride: enable QSPI and NOR flash Viken Dadhaniya
2026-04-15  9:49   ` Konrad Dybcio
2026-04-14 17:08 ` [PATCH v2 6/7] arm64: dts: qcom: kodiak: Add QSPI memory interconnect path Viken Dadhaniya
2026-04-14 17:56   ` Dmitry Baryshkov
2026-04-15  9:49   ` Konrad Dybcio
2026-04-14 17:08 ` [PATCH v2 7/7] arm64: dts: qcom: sc7180: " Viken Dadhaniya
2026-04-14 17:56   ` Dmitry Baryshkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fe30cca9-c348-4ab2-b190-33016242aa64@oss.qualcomm.com \
    --to=konrad.dybcio@oss.qualcomm.com \
    --cc=andersson@kernel.org \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=cros-qcom-dts-watchers@chromium.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konradybcio@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=viken.dadhaniya@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox