Skip to contentSkip to conversation

cpufreq: longhaul: Make array speeds static const

PATCH Superseded Colin Ian King 3 participants 5 messages Nov 3, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: longhaul: Make array speeds static const

Don't populate the read-only array speeds on the stack but instead make it static. Also makes the object code a little smaller.

---
 drivers/cpufreq/longhaul.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/longhaul.c +1 -1
index 3e000e1a75c6..25f8ef7bac47 100644
@@ -407,7 +407,7 @@ static int guess_fsb(int mult)
 {
 	int speed = cpu_khz / 1000;
 	int i;
-	int speeds[] = { 666, 1000, 1333, 2000 };
+	static const int speeds[] = { 666, 1000, 1333, 2000 };
 	int f_max, f_min;
 
 	for (i = 0; i < 4; i++) {
Signature · 1 line
2.38.1
#1 lore raw
Quoted 2 lines · Colin Ian King

Don't populate the read-only array speeds on the stack but instead make it static. Also makes the object code a little smaller.

[]

drivers/cpufreq/longhaul.c

Quoted 1 line
drivers/cpufreq/longhaul.c +0 -0

[]

drivers/cpufreq/longhaul.c static int guess_fsb(int mult) · line 413

Quoted 9 lines
drivers/cpufreq/longhaul.c +1 -1
@@ -407,7 +407,7 @@ static int guess_fsb(int mult)
 {
 	int speed = cpu_khz / 1000;
 	int i;
-	int speeds[] = { 666, 1000, 1333, 2000 };
+	static const int speeds[] = { 666, 1000, 1333, 2000 };
 	int f_max, f_min;
 
 	for (i = 0; i < 4; i++) {

style trivia: the loop test is probably better using ARRAY_SIZE

	for (i = 0; i < ARRAY_SIZE(speeds); i++)
#2 lore raw
Quoted 14 lines · Joe Perches
Quoted 2 lines · Colin Ian King

Don't populate the read-only array speeds on the stack but instead make it static. Also makes the object code a little smaller.

[]

drivers/cpufreq/longhaul.c

Quoted 1 line
drivers/cpufreq/longhaul.c +0 -0

[]

Quoted 8 lines
drivers/cpufreq/longhaul.c +1 -1
@@ -407,7 +407,7 @@ static int guess_fsb(int mult)
  {
  	int speed = cpu_khz / 1000;
  	int i;
-	int speeds[] = { 666, 1000, 1333, 2000 };
+	static const int speeds[] = { 666, 1000, 1333, 2000 };
  	int f_max, f_min;
 
Quoted 6 lines

drivers/cpufreq/longhaul.c static int guess_fsb(int mult) · line 413

Quoted 1 line
drivers/cpufreq/longhaul.c +0 -0
  	for (i = 0; i < 4; i++) {

style trivia: the loop test is probably better using ARRAY_SIZE

	for (i = 0; i < ARRAY_SIZE(speeds); i++)

I'll send a V2 for that. Good idea.

Colin

maintainer
#3 lore raw
In reply to Colin Ian King
Quoted 2 lines · Colin Ian King

Don't populate the read-only array speeds on the stack but instead make it static. Also makes the object code a little smaller.

How will that benefit ? I am just looking for a valid answer in commit log.

Quoted 10 lines
---
 drivers/cpufreq/longhaul.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/longhaul.c +0 -0
index 3e000e1a75c6..25f8ef7bac47 100644

drivers/cpufreq/longhaul.c static int guess_fsb(int mult) · line 410

Quoted 5 lines
drivers/cpufreq/longhaul.c +1 -1
@@ -407,7 +407,7 @@ static int guess_fsb(int mult)
 {
 	int speed = cpu_khz / 1000;
 	int i;
-	int speeds[] = { 666, 1000, 1333, 2000 };
+	static const int speeds[] = { 666, 1000, 1333, 2000 };

Why not make it global then ?

Signature · 1 line
viresh
#4 lore raw
Quoted 5 lines · Viresh Kumar
Quoted 2 lines · Colin Ian King

Don't populate the read-only array speeds on the stack but instead make it static. Also makes the object code a little smaller.

How will that benefit ? I am just looking for a valid answer in commit log.

When the array is non-static there will be some executable code to put these values into the array that's on the stack (e.g. at run time). When it is static the array is filled at compile time and there is no executable code required to populate the array at run time.

Quoted 6 lines
Quoted 6 lines
---
  drivers/cpufreq/longhaul.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/cpufreq/longhaul.c static int guess_fsb(int mult) · line 410

Quoted 10 lines
drivers/cpufreq/longhaul.c +1 -1
index 3e000e1a75c6..25f8ef7bac47 100644
@@ -407,7 +407,7 @@ static int guess_fsb(int mult)
  {
  	int speed = cpu_khz / 1000;
  	int i;
-	int speeds[] = { 666, 1000, 1333, 2000 };
+	static const int speeds[] = { 666, 1000, 1333, 2000 };

Why not make it global then ?

Making it static inside the function limits the scope to the function and so it's not globally visible. We don't like making stuff global unless we really need to.

Colin