Skip to contentSkip to conversation

clk: qcom: Fix error checking for devm_clk_hw_get_clk()

PATCH In review Yan Zhen 5 participants 7 messages Aug 27, 2024 – Aug 29, 2024

Subsystems (3)
lore
Share & tools
lore

Yan Zhen

author
#0 lore raw

PATCH v3 1/1 clk: qcom: Fix error checking for devm_clk_hw_get_clk()

The devm_clk_hw_get_clk() function returns error pointers. It never returns NULL. Update the check accordingly.

Fixes 8737ec830ee3 ("clk: qcom: common: Add interconnect clocks support")'

---

Changes in v3:
- Providing a "fixes" tag blaming the commit.

 drivers/clk/qcom/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/qcom/common.c +2 -2
index 33cc1f73c69d..5a9e653916ea 100644
@@ -273,8 +273,8 @@ static int qcom_cc_icc_register(struct device *dev,
 		icd[i].slave_id = desc->icc_hws[i].slave_id;
 		hws = &desc->clks[desc->icc_hws[i].clk_id]->hw;
 		icd[i].clk = devm_clk_hw_get_clk(dev, hws, "icc");
-		if (!icd[i].clk)
-			return dev_err_probe(dev, -ENOENT,
+		if (IS_ERR(icd[i].clk))
+			return dev_err_probe(dev, PTR_ERR(icd[i].clk),
 					     "(%d) clock entry is null\n", i);
 		icd[i].name = clk_hw_get_name(hws);
 	}
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Quoting Yan Zhen (2024-08-26 19:52:52)

Quoted 2 lines

The devm_clk_hw_get_clk() function returns error pointers. It never returns NULL. Update the check accordingly.

It can return NULL if the 'hw' pointer passed in is NULL.

#3 lore raw
In reply to Stephen Boyd
Quoted 5 lines · Stephen Boyd

Quoting Yan Zhen (2024-08-26 19:52:52)

Quoted 2 lines

The devm_clk_hw_get_clk() function returns error pointers. It never returns NULL. Update the check accordingly.

It can return NULL if the 'hw' pointer passed in is NULL.

No, it will crash:

        WARN_ON_ONCE(dev != hw->core->dev);

Furthermore, clk_hw_get_clk() also doesn't have NULL checks and will crash if NULL is passed as hw.

struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id)

{
        struct device *dev = hw->core->dev;
Signature · 2 lines
With best wishes
Dmitry
maintainer
#4 lore raw

Quoting Dmitry Baryshkov (2024-08-29 02:06:51)

Quoted 5 lines · Stephen Boyd
Quoted 4 lines

Quoting Yan Zhen (2024-08-26 19:52:52)

Quoted 2 lines

The devm_clk_hw_get_clk() function returns error pointers. It never returns NULL. Update the check accordingly.

Quoted 8 lines
Quoted 1 line

It can return NULL if the 'hw' pointer passed in is NULL.

No, it will crash:

        WARN_ON_ONCE(dev != hw->core->dev);

Furthermore, clk_hw_get_clk() also doesn't have NULL checks and will crash if NULL is passed as hw.

Ah, thanks. I misread it as clk_hw_create_clk().

Reviewed-by on v3 1/1
#5 lore raw
In reply to Yan Zhen
Quoted 5 lines · Yan Zhen

The devm_clk_hw_get_clk() function returns error pointers. It never returns NULL. Update the check accordingly.

Fixes 8737ec830ee3 ("clk: qcom: common: Add interconnect clocks support")'
Quoted 8 lines

---

Changes in v3:
- Providing a "fixes" tag blaming the commit.

 drivers/clk/qcom/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#6 lore raw
In reply to Yan Zhen

Le 27/08/2024 à 04:52, Yan Zhen a écrit :

Quoted 18 lines

The devm_clk_hw_get_clk() function returns error pointers. It never returns NULL. Update the check accordingly.

Fixes 8737ec830ee3 ("clk: qcom: common: Add interconnect clocks support")'

---

Changes in v3:
- Providing a "fixes" tag blaming the commit.

  drivers/clk/qcom/common.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/qcom/common.c +0 -0
index 33cc1f73c69d..5a9e653916ea 100644

drivers/clk/qcom/common.c static int qcom_cc_icc_register(struct device *dev, · line 278

Quoted 8 lines
drivers/clk/qcom/common.c +2 -2
@@ -273,8 +273,8 @@ static int qcom_cc_icc_register(struct device *dev,
  		icd[i].slave_id = desc->icc_hws[i].slave_id;
  		hws = &desc->clks[desc->icc_hws[i].clk_id]->hw;
  		icd[i].clk = devm_clk_hw_get_clk(dev, hws, "icc");
-		if (!icd[i].clk)
-			return dev_err_probe(dev, -ENOENT,
+		if (IS_ERR(icd[i].clk))
+			return dev_err_probe(dev, PTR_ERR(icd[i].clk),
  					     "(%d) clock entry is null\n", i);

Nitpick: Maybe the message could be updated as-well?

CJ

Quoted 2 lines
drivers/clk/qcom/common.c +0 -0
  		icd[i].name = clk_hw_get_name(hws);
  	}