[PATCH][next] clk: moxart: Make read-only array div_idx static const

Colin Ian King posted 1 patch 3 months, 3 weeks ago
drivers/clk/clk-moxart.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH][next] clk: moxart: Make read-only array div_idx static const
Posted by Colin Ian King 3 months, 3 weeks ago
Don't populate the read-only array div_idx on the stack at run time,
instead make it static const.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/clk/clk-moxart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk-moxart.c b/drivers/clk/clk-moxart.c
index 3786a0153ad1..4d34d1d18dbd 100644
--- a/drivers/clk/clk-moxart.c
+++ b/drivers/clk/clk-moxart.c
@@ -58,7 +58,7 @@ static void __init moxart_of_apb_clk_init(struct device_node *node)
 	struct clk_hw *hw;
 	struct clk *pll_clk;
 	unsigned int div, val;
-	unsigned int div_idx[] = { 2, 3, 4, 6, 8};
+	static const unsigned int div_idx[] = { 2, 3, 4, 6, 8};
 	const char *name = node->name;
 	const char *parent_name;
 
-- 
2.49.0
Re: [PATCH][next] clk: moxart: Make read-only array div_idx static const
Posted by Stephen Boyd 3 months, 3 weeks ago
Quoting Colin Ian King (2025-06-19 01:30:35)
> Don't populate the read-only array div_idx on the stack at run time,
> instead make it static const.

Why? This is in __init code so it can be thrown away if it stays on the
stack.
Re: [PATCH][next] clk: moxart: Make read-only array div_idx static const
Posted by Krzysztof Kozlowski 3 months, 3 weeks ago
On 19/06/2025 21:53, Stephen Boyd wrote:
> Quoting Colin Ian King (2025-06-19 01:30:35)
>> Don't populate the read-only array div_idx on the stack at run time,
>> instead make it static const.
> 
> Why? This is in __init code so it can be thrown away if it stays on the
> stack.

Indeed previous code could be discarded, now will be in rodata, but we
save several instructions runtime on copying it. Plus the actual binary
will be slower (really less code), so also loading it will be faster.

Best regards,
Krzysztof
Re: [PATCH][next] clk: moxart: Make read-only array div_idx static const
Posted by Krzysztof Kozlowski 3 months, 2 weeks ago
On 19/06/2025 22:18, Krzysztof Kozlowski wrote:
> On 19/06/2025 21:53, Stephen Boyd wrote:
>> Quoting Colin Ian King (2025-06-19 01:30:35)
>>> Don't populate the read-only array div_idx on the stack at run time,
>>> instead make it static const.
>>
>> Why? This is in __init code so it can be thrown away if it stays on the
>> stack.
> 
> Indeed previous code could be discarded, now will be in rodata, but we
> save several instructions runtime on copying it. Plus the actual binary
> will be slower (really less code), so also loading it will be faster.


s/slower/smaller/

Best regards,
Krzysztof
Re: [PATCH][next] clk: moxart: Make read-only array div_idx static const
Posted by Krzysztof Kozlowski 3 months, 3 weeks ago
On 19/06/2025 10:30, Colin Ian King wrote:
> Don't populate the read-only array div_idx on the stack at run time,
> instead make it static const.
> 
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof