* [PATCH] clk: uniphier: mux: fix signedness bug in get_parent
@ 2026-03-18 11:02 Anas Iqbal
2026-03-18 17:05 ` Brian Masney
2026-03-24 0:44 ` Stephen Boyd
0 siblings, 2 replies; 4+ messages in thread
From: Anas Iqbal @ 2026-03-18 11:02 UTC (permalink / raw)
To: mturquette, sboyd, linux-clk
Cc: hayashi.kunihiko, mhiramat, yamada.masahiro, linux-arm-kernel,
linux-kernel, Anas Iqbal
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.
Fixes: 734d82f4a678 ("clk: uniphier: add core support code for UniPhier clock driver")
Signed-off-by: Anas Iqbal <mohd.abd.6602@gmail.com>
---
drivers/clk/uniphier/clk-uniphier-mux.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/uniphier/clk-uniphier-mux.c b/drivers/clk/uniphier/clk-uniphier-mux.c
index 1998e9d4cfc0..f3b21ea96649 100644
--- a/drivers/clk/uniphier/clk-uniphier-mux.c
+++ b/drivers/clk/uniphier/clk-uniphier-mux.c
@@ -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 = {
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] clk: uniphier: mux: fix signedness bug in get_parent
2026-03-18 11:02 [PATCH] clk: uniphier: mux: fix signedness bug in get_parent Anas Iqbal
@ 2026-03-18 17:05 ` Brian Masney
2026-03-24 0:44 ` Stephen Boyd
1 sibling, 0 replies; 4+ messages in thread
From: Brian Masney @ 2026-03-18 17:05 UTC (permalink / raw)
To: Anas Iqbal
Cc: mturquette, sboyd, linux-clk, hayashi.kunihiko, mhiramat,
yamada.masahiro, linux-arm-kernel, linux-kernel
On Wed, Mar 18, 2026 at 11:02:51AM +0000, Anas Iqbal wrote:
> 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.
>
> Fixes: 734d82f4a678 ("clk: uniphier: add core support code for UniPhier clock driver")
> Signed-off-by: Anas Iqbal <mohd.abd.6602@gmail.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] clk: uniphier: mux: fix signedness bug in get_parent
2026-03-18 11:02 [PATCH] clk: uniphier: mux: fix signedness bug in get_parent Anas Iqbal
2026-03-18 17:05 ` Brian Masney
@ 2026-03-24 0:44 ` Stephen Boyd
2026-03-25 5:11 ` Kunihiko Hayashi
1 sibling, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2026-03-24 0:44 UTC (permalink / raw)
To: Anas Iqbal, linux-clk, mturquette
Cc: hayashi.kunihiko, mhiramat, yamada.masahiro, linux-arm-kernel,
linux-kernel, Anas Iqbal
Quoting Anas Iqbal (2026-03-18 04:02:51)
> 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.
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] clk: uniphier: mux: fix signedness bug in get_parent
2026-03-24 0:44 ` Stephen Boyd
@ 2026-03-25 5:11 ` Kunihiko Hayashi
0 siblings, 0 replies; 4+ messages in thread
From: Kunihiko Hayashi @ 2026-03-25 5:11 UTC (permalink / raw)
To: Stephen Boyd, Anas Iqbal, linux-clk, mturquette
Cc: mhiramat, linux-arm-kernel, linux-kernel
Hi,
On 2026/03/24 9:44, Stephen Boyd wrote:
> Quoting Anas Iqbal (2026-03-18 04:02:51)
>> 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.
>
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-25 5:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18 11:02 [PATCH] clk: uniphier: mux: fix signedness bug in get_parent Anas Iqbal
2026-03-18 17:05 ` Brian Masney
2026-03-24 0:44 ` Stephen Boyd
2026-03-25 5:11 ` Kunihiko Hayashi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox