cpufreq: longhaul: Make array speeds static const
Subsystems (2)
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
@@ -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
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++)
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
-0for (i =0 ; i <4 ; i++) {style trivia: the loop test is probably better using
ARRAY_SIZEfor (i = 0; i < ARRAY_SIZE(speeds); i++)
I'll send a V2 for that. Good idea.
Colin
Viresh Kumar
maintainerQuoted 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
Signed-off-by Colin Ian King <[email protected]>--- drivers/cpufreq/longhaul.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpufreq/longhaul.c +0
-0
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
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
Signed-off-by Colin Ian King <[email protected]>--- 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@@ -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