clk: uniphier: mux: fix signedness bug in get_parent
Subsystems (2)
PATCH 1/1 clk: uniphier: mux: fix signedness bug in get_parent
The uniphier_clk_mux_get_parent() function returns a u8, but propagates negative error codes such as -EINVAL and regmap_read() failures. These values are implicitly converted to large unsigned integers, resulting in invalid parent indices.
The clk_ops.get_parent() callback is expected to return a valid parent index and does not support error codes. Fix this by returning 0 as a safe fallback in error cases.
--- drivers/clk/uniphier/clk-uniphier-mux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/uniphier/clk-uniphier-mux.c +2 -2
@@ -38,13 +38,13 @@ static u8 uniphier_clk_mux_get_parent(struct clk_hw *hw) ret =regmap_read (mux->regmap, mux->reg, &val);if (ret) -return ret; +return 0 ;/* fallback to parent 0 on error */ for (i =0 ; i < num_parents; i++)if ((mux->masks[i] & val) == mux->vals[i])return i; -return -EINVAL ; +return 0 ;/* default fallback */ }static const struct clk_ops uniphier_clk_mux_ops = {
Signature · 1 line
2.43.0
Quoted 11 lines · Anas Iqbal
The
uniphier_clk_mux_get_parent()function returns a u8, but propagates negative error codes such as-EINVALandregmap_read()failures. These values are implicitly converted to large unsigned integers, resulting in invalid parent indices.The
clk_ops.get_parent()callback is expected to return a valid parent index and does not support error codes. Fix this by returning 0 as a safe fallback in error cases.Fixes 734d82f4a678 ("clk: uniphier: add core support code for UniPhier clock driver")Signed-off-by Anas Iqbal <[email protected]>
Stephen Boyd
maintainerQuoting Anas Iqbal (2026-03-18 04:02:51)
Quoted 8 lines
The
uniphier_clk_mux_get_parent()function returns a u8, but propagates negative error codes such as-EINVALandregmap_read()failures. These values are implicitly converted to large unsigned integers, resulting in invalid parent indices.The
clk_ops.get_parent()callback is expected to return a valid parent index and does not support error codes. Fix this by returning 0 as a safe fallback in error cases.
A large number will exceed the number of parents possible for the clk and turn into a failure to find the parent in the parent map. There's nothing to do here besides implement clk_ops::get_parent_hw()[1] and fix all the drivers.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/log/?h=clk-parent-rewrite
Kunihiko Hayashi
maintainerHi,
Quoted 10 lines · Stephen Boyd
Quoting Anas Iqbal (2026-03-18 04:02:51)
Quoted 8 lines
The
uniphier_clk_mux_get_parent()function returns a u8, but propagates negative error codes such as-EINVALandregmap_read()failures. These values are implicitly converted to large unsigned integers, resulting in invalid parent indices.The
clk_ops.get_parent()callback is expected to return a valid parent index and does not support error codes. Fix this by returning 0 as a safe fallback in error cases.
Quoted 7 lines
A large number will exceed the number of parents possible for the clk and turn into a failure to find the parent in the parent map. There's nothing to do here besides implement clk_ops::get_parent_hw()[1] and fix all the drivers.
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/log/?h=clk-parent-rewrite
Certainly, the return value of .get_parent() is now u8, which doesn't correctly detect an error in the function.
Some other implementations prevent .get_parent() from detecting regmap_read() errors, but if it does, the read value is undefined.
If access to the parent fails, the only option is to propagate the error as Stephen suggested, however, that affects all drivers, not just this one.
Thank you,
---
Best Regards
Kunihiko Hayashi