Skip to contentSkip to conversation

clk: qcom: rcg2: validate frequency table entry in __clk_rcg2_shared_set_rate()

PATCH In review Gabor Juhos 2 participants 3 messages Oct 27 – Oct 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: qcom: rcg2: validate frequency table entry in __clk_rcg2_shared_set_rate()

Commit aec8c0e28ce4 ("clk: qcom: rcg2: add clk_rcg2_shared_floor_ops") removed validating of the frequency table entry pointer returned by the qcom_find_freq() or the qcom_find_freq_floor() functions.

Since both functions can return NULL and the pointer is passed directly to the __clk_rcg2_configure() function where it gets dereferenced unconditionally, it could cause a panic.

Restore the sanity check removed by the mentioned commit in order to avoid a possible NULL pointer dereference.

Compile tested only.

Fixes aec8c0e28ce4 ("clk: qcom: rcg2: add clk_rcg2_shared_floor_ops")
---
 drivers/clk/qcom/clk-rcg2.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/qcom/clk-rcg2.c +3 -0
index d7914e59129f..260e90f53461 100644
@@ -1385,6 +1385,9 @@ static int __clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate,
 		return -EINVAL;
 	}
 
+	if (!f)
+		return -EINVAL;
+
 	/*
 	 * In case clock is disabled, update the M, N and D registers, cache
 	 * the CFG value in parked_cfg and don't hit the update bit of CMD

---
base-commit: 55981579b27b6541aeeab81c768f248dba0491ac
change-id: 20261027-rcg2-avoid-null-ptr-deref-0885433584af

Best regards,

Signature · 1 line
Gabor Juhos <[email protected]>
#1 lore raw
Quoted 24 lines · Gabor Juhos

Commit aec8c0e28ce4 ("clk: qcom: rcg2: add clk_rcg2_shared_floor_ops") removed validating of the frequency table entry pointer returned by the qcom_find_freq() or the qcom_find_freq_floor() functions.

Since both functions can return NULL and the pointer is passed directly to the __clk_rcg2_configure() function where it gets dereferenced unconditionally, it could cause a panic.

Restore the sanity check removed by the mentioned commit in order to avoid a possible NULL pointer dereference.

Compile tested only.

Fixes aec8c0e28ce4 ("clk: qcom: rcg2: add clk_rcg2_shared_floor_ops")
---
 drivers/clk/qcom/clk-rcg2.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/qcom/clk-rcg2.c +0 -0
index d7914e59129f..260e90f53461 100644

drivers/clk/qcom/clk-rcg2.c static int __clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate, · line 1390

Quoted 6 lines
drivers/clk/qcom/clk-rcg2.c +3 -0
@@ -1385,6 +1385,9 @@ static int __clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate,
 		return -EINVAL;
 	}
 
+	if (!f)
+		return -EINVAL;
+

Normally, the CCF calls .determine_rate before .set_rate. The floor determination helper already rejects a request below the lowest supported
frequency:

 ```c
   if (!f)
      return -EINVAL;
 ```

So an ordinary clk_set_rate() request below the table minimum should fail during rate determination and typically not reach
__clk_rcg2_shared_set_rate().

Signature · 2 lines
Thanks,
Taniya Das
#2 lore raw

2026. 10. 27. 19:24 keltezéssel, Taniya Das írta:

Quoted 38 lines · Gabor Juhos
Quoted 24 lines

Commit aec8c0e28ce4 ("clk: qcom: rcg2: add clk_rcg2_shared_floor_ops") removed validating of the frequency table entry pointer returned by the qcom_find_freq() or the qcom_find_freq_floor() functions.

Since both functions can return NULL and the pointer is passed directly to the __clk_rcg2_configure() function where it gets dereferenced unconditionally, it could cause a panic.

Restore the sanity check removed by the mentioned commit in order to avoid a possible NULL pointer dereference.

Compile tested only.

Fixes aec8c0e28ce4 ("clk: qcom: rcg2: add clk_rcg2_shared_floor_ops")
---
 drivers/clk/qcom/clk-rcg2.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/qcom/clk-rcg2.c +0 -0
index d7914e59129f..260e90f53461 100644

drivers/clk/qcom/clk-rcg2.c static int __clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate, · line 1390

Quoted 6 lines
drivers/clk/qcom/clk-rcg2.c +3 -0
@@ -1385,6 +1385,9 @@ static int __clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate,
 		return -EINVAL;
 	}
 
+	if (!f)
+		return -EINVAL;
+

Normally, the CCF calls .determine_rate before .set_rate. The floor determination helper already rejects a request below the lowest supported
frequency:

Quoted 10 lines
 ```c
   if (!f)
      return -EINVAL;
 ```

So an ordinary clk_set_rate() request below the table minimum should fail during rate determination and typically not reach
__clk_rcg2_shared_set_rate().

Thank you for the explanation, it makes sense.
In this case, we don't need the patch.

Regards,
Gabor