Skip to contentSkip to conversation

cpufreq: longhaul: Make array speeds static const

PATCH Applied Colin Ian King 2 participants 2 messages Nov 3, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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. Replace hard-coded loop array bounds with ARRAY_SIZE.

---
V2: replace 4 with ARRAY_SIZE in for-loop as suggested by Joe Perches.

---
 drivers/cpufreq/longhaul.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/longhaul.c +2 -2
index 3e000e1a75c6..4c57c6725c13 100644
@@ -407,10 +407,10 @@ 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++) {
+	for (i = 0; i < ARRAY_SIZE(speeds); i++) {
 		f_max = ((speeds[i] * mult) + 50) / 100;
 		f_max += (ROUNDING / 2);
 		f_min = f_max - ROUNDING;
Signature · 1 line
2.38.1
maintainer Applied
#1 lore raw
Quoted 20 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. Replace hard-coded loop array bounds with ARRAY_SIZE.

---
V2: replace 4 with ARRAY_SIZE in for-loop as suggested by Joe Perches.

---
 drivers/cpufreq/longhaul.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/longhaul.c +0 -0
index 3e000e1a75c6..4c57c6725c13 100644
@@ -407,10 +407,10 @@ static int guess_fsb(int mult)
 {
        int speed = cpu_khz / 1000;
        int i;

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

Quoted 10 lines
drivers/cpufreq/longhaul.c +2 -3
-       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++) {
+       for (i = 0; i < ARRAY_SIZE(speeds); i++) {
                f_max = ((speeds[i] * mult) + 50) / 100;
                f_max += (ROUNDING / 2);
                f_min = f_max - ROUNDING;
--

Applied as 6.2 material, thanks!