Fix NULL dereference in clk_composite_set_rate()
cover Fix NULL dereference in clk_composite_set_rate()
On sandbox it's possible to trigger NULL dereference when setting rate of a composite clock. It happens because sandbox composite divider does not implement set_rate() operation. This series adds NULL check and a test cases for clk_set_rate().
Igor Prusov (2):
clk: Check that composite clock's div has set_rate()
dm: test: clk: Add test for ccf clk_set_rate()
drivers/clk/clk-composite.c | 2 +- test/dm/clk_ccf.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
PATCH 1/2 clk: Check that composite clock's div has set_rate()
It's possible for composite clocks to have a divider that does not implement set_rate() operation. For example, sandbox_clk_composite() registers composite clock with a divider that only has get_rate(). Currently clk_composite_set_rate() only checks thate rate_ops are present, so for sandbox it will cause NULL dereference during clk_set_rate().
This patch adds rate_ops->set_rate check tp clk_composite_set_rate().
---
drivers/clk/clk-composite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk-composite.c +1 -1
@@ -66,7 +66,7 @@ static ulong clk_composite_set_rate(struct clk *clk, unsigned long rate)const struct clk_ops *rate_ops = composite->rate_ops;struct clk *clk_rate = composite->rate; -if (rate && rate_ops) +if (rate && rate_ops && rate_ops->set_rate)return rate_ops->set_rate (clk_rate, rate);else return clk_get_rate (clk);
Signature · 1 line
2.34.1
Re: [PATCH 1/2] clk: Check that composite clock's div has set_rate()
Quoted 20 lines · Igor Prusov
It's possible for composite clocks to have a divider that does not implement
set_rate()operation. For example,sandbox_clk_composite()registers composite clock with a divider that only hasget_rate(). Currentlyclk_composite_set_rate()only checks thaterate_opsare present, so for sandbox it will cause NULL dereference duringclk_set_rate().This patch adds
rate_ops->set_ratecheck tpclk_composite_set_rate().Signed-off-by Igor Prusov <[email protected]>---
drivers/clk/clk-composite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/clk/clk-composite.c +0
-0
drivers/clk/clk-composite.c static ulong clk_composite_set_rate(struct clk *clk, unsigned long rate) · line 72
Quoted 8 lines
drivers/clk/clk-composite.c +1
-1@@ -66,7 +66,7 @@ static ulong clk_composite_set_rate(struct clk *clk, unsigned long rate)const struct clk_ops *rate_ops = composite->rate_ops;struct clk *clk_rate = composite->rate; -if (rate && rate_ops) +if (rate && rate_ops && rate_ops->set_rate)return rate_ops->set_rate (clk_rate, rate);else return clk_get_rate (clk);
PATCH 2/2 dm: test: clk: Add test for ccf clk_set_rate()
In reply to Igor PrusovAdd a simple test case which sets clock rate to its current value.
---
test/dm/clk_ccf.c | 9 +++++++++ 1 file changed, 9 insertions(+)
test/dm/clk_ccf.c +9 -0
@@ -63,6 +63,9 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) rate =clk_get_parent_rate (clk);ut_asserteq (rate,60000000 ); + rate =clk_set_rate (clk,60000000 ); +ut_asserteq (rate, -ENOSYS ); + rate =clk_get_rate (clk);ut_asserteq (rate,60000000 );
@@ -87,6 +90,9 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)ut_asserteq_str ("pll3_80m" , pclk->dev->name);ut_asserteq (CLK_SET_RATE_PARENT , pclk->flags); + rate =clk_set_rate (clk,80000000 ); +ut_asserteq (rate, -ENOSYS ); + rate =clk_get_rate (clk);ut_asserteq (rate,80000000 );
@@ -108,6 +114,9 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) rate =clk_get_rate (clk);ut_asserteq (rate,60000000 ); + rate =clk_set_rate (clk,60000000 ); +ut_asserteq (rate,60000000 ); +#if CONFIG_IS_ENABLED (CLK_CCF )/* Test clk tree enable/disable */ ret =clk_get_by_id (SANDBOX_CLK_I2C_ROOT , &clk);
Signature · 1 line
2.34.1
Re: [PATCH 2/2] dm: test: clk: Add test for ccf clk_set_rate()
Quoted 33 lines · Igor Prusov
Add a simple test case which sets clock rate to its current value.
Signed-off-by Igor Prusov <[email protected]>---
test/dm/clk_ccf.c | 9 +++++++++ 1 file changed, 9 insertions(+)test/dm/clk_ccf.c +6
-0@@ -63,6 +63,9 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) rate =clk_get_parent_rate (clk);ut_asserteq (rate,60000000 ); + rate =clk_set_rate (clk,60000000 ); +ut_asserteq (rate, -ENOSYS ); + rate =clk_get_rate (clk);ut_asserteq (rate,60000000 );@@ -87,6 +90,9 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)ut_asserteq_str ("pll3_80m" , pclk->dev->name);ut_asserteq (CLK_SET_RATE_PARENT , pclk->flags); + rate =clk_set_rate (clk,80000000 ); +ut_asserteq (rate, -ENOSYS ); + rate =clk_get_rate (clk);ut_asserteq (rate,80000000 );
test/dm/clk_ccf.c static int dm_test_clk_ccf(struct unit_test_state *uts) · line 122
Quoted 9 lines
test/dm/clk_ccf.c +3
-0@@ -108,6 +114,9 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) rate =clk_get_rate (clk);ut_asserteq (rate,60000000 ); + rate =clk_set_rate (clk,60000000 ); +ut_asserteq (rate,60000000 ); +#if CONFIG_IS_ENABLED (CLK_CCF )/* Test clk tree enable/disable */ ret =clk_get_by_id (SANDBOX_CLK_I2C_ROOT , &clk);
Sean Anderson
AppliedQuoted 11 lines · Igor Prusov
On sandbox it's possible to trigger NULL dereference when setting rate of a composite clock. It happens because sandbox composite divider does not implement
set_rate()operation. This series adds NULL check and a test cases forclk_set_rate().Igor Prusov (2):
clk: Check that composite clock's div hasset_rate()
dm: test: clk: Add test for ccfclk_set_rate()[...]
Applied, thanks!
[1/2] clk: Check that composite clock's div has set_rate()
https://source.denx.de/u-boot/custodians/u-boot-clk/-/commit/54d7da773062 [2/2] dm: test: clk: Add test for ccf clk_set_rate() https://source.denx.de/u-boot/custodians/u-boot-clk/-/commit/9e0250321a0d
Best regards,
Signature · 1 line
Sean Anderson <[email protected]>