[PATCH v2] ufs: uclass: fix potential unitialised use

Casey Connolly casey.connolly at linaro.org
Thu Jan 8 21:14:01 CET 2026


There's a few weird codepaths here including some that return err before
it gets set. Clean things up and drop the unnecessary label.

Also make a note about returning 0 when ref clk frequency is 0.

Signed-off-by: Casey Connolly <casey.connolly at linaro.org>
---
 drivers/ufs/ufs-uclass.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 3c8e4299259c..c6ef93dd101c 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -1862,45 +1862,43 @@ static int ufshcd_set_dev_ref_clk(struct ufs_hba *hba)
 
 	/* get ref_clk */
 	ref_clk = devm_clk_get(hba->dev, "ref_clk");
 	if (IS_ERR((const void *)ref_clk)) {
-		err = PTR_ERR(ref_clk);
-		goto out;
+		return PTR_ERR(ref_clk);
 	}
 
 	host_ref_clk_freq = ufshcd_parse_dev_ref_clk_freq(hba, ref_clk);
-	if (host_ref_clk_freq == REF_CLK_FREQ_INVAL)
+	if (host_ref_clk_freq == REF_CLK_FREQ_INVAL) {
 		dev_err(hba->dev,
 			"invalid ref_clk setting = %ld\n", clk_get_rate(ref_clk));
-
-	if (host_ref_clk_freq == REF_CLK_FREQ_INVAL)
-		goto out;
+		/* FIXME: qcom platforms don't have this wired up yet but seem to work anyway */
+		return 0;
+	}
 
 	err = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR,
 				      QUERY_ATTR_IDN_REF_CLK_FREQ, 0, 0, &dev_ref_clk_freq);
 
 	if (err) {
 		dev_err(hba->dev, "failed reading bRefClkFreq. err = %d\n", err);
-		goto out;
+		return err;
 	}
 
 	if (dev_ref_clk_freq == host_ref_clk_freq)
-		goto out; /* nothing to update */
+		return 0; /* nothing to update */
 
 	err = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
 				      QUERY_ATTR_IDN_REF_CLK_FREQ, 0, 0, &host_ref_clk_freq);
 
 	if (err) {
 		dev_err(hba->dev, "bRefClkFreq setting to %lu Hz failed\n",
 			ufs_ref_clk_freqs[host_ref_clk_freq].freq_hz);
-		goto out;
+		return err;
 	}
 
 	dev_dbg(hba->dev, "bRefClkFreq setting to %lu Hz succeeded\n",
 		ufs_ref_clk_freqs[host_ref_clk_freq].freq_hz);
 
-out:
-	return err;
+	return 0;
 }
 
 /**
  * ufshcd_get_max_pwr_mode - reads the max power mode negotiated with device
-- 
2.51.0



More information about the U-Boot mailing list