Skip to contentSkip to conversation

cpufreq: highbank: do not initialize array with a loop

PATCH Superseded Emilio López 3 participants 6 messages Feb 24, 2013 – Feb 25, 2013 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: highbank: do not initialize array with a loop

As uninitialized array members will be initialized to zero, we can avoid using a for loop by setting a value to it.

---
Note that I don't own any device using this driver, it has only been compile tested, but it shouldn't cause any issues.

 drivers/cpufreq/highbank-cpufreq.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/cpufreq/highbank-cpufreq.c +1 -5
index 66e3a71..30d4ae1 100644
@@ -28,13 +28,9 @@
 
 static int hb_voltage_change(unsigned int freq)
 {
-	int i;
-	u32 msg[HB_CPUFREQ_IPC_LEN];
+	u32 msg[HB_CPUFREQ_IPC_LEN] = {HB_CPUFREQ_CHANGE_NOTE};
 
-	msg[0] = HB_CPUFREQ_CHANGE_NOTE;
 	msg[1] = freq / 1000000;
-	for (i = 2; i < HB_CPUFREQ_IPC_LEN; i++)
-		msg[i] = 0;
 
 	return pl320_ipc_transmit(msg);
 }
Signature · 7 lines
1.8.2.rc0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#1 lore raw
Quoted 16 lines · Emilio López

As uninitialized array members will be initialized to zero, we can avoid using a for loop by setting a value to it.

---
Note that I don't own any device using this driver, it has only been compile tested, but it shouldn't cause any issues.

 drivers/cpufreq/highbank-cpufreq.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/cpufreq/highbank-cpufreq.c +0 -0
index 66e3a71..30d4ae1 100644

drivers/cpufreq/highbank-cpufreq.c line 33

Quoted 9 lines
drivers/cpufreq/highbank-cpufreq.c +1 -3
@@ -28,13 +28,9 @@
 
 static int hb_voltage_change(unsigned int freq)
 {
-       int i;
-       u32 msg[HB_CPUFREQ_IPC_LEN];
+       u32 msg[HB_CPUFREQ_IPC_LEN] = {HB_CPUFREQ_CHANGE_NOTE};
 
-       msg[0] = HB_CPUFREQ_CHANGE_NOTE;
        msg[1] = freq / 1000000;

I think this can also be part of the definition of array, isn't it?

So it would be something like:

u32 msg[HB_CPUFREQ_IPC_LEN] = {HB_CPUFREQ_CHANGE_NOTE, freq / 1000000};

Quoted 13 lines
drivers/cpufreq/highbank-cpufreq.c +0 -3
-       for (i = 2; i < HB_CPUFREQ_IPC_LEN; i++)
-               msg[i] = 0;
 
        return pl320_ipc_transmit(msg);
 }
--

1.8.2.rc0

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw

Hello,

Quoted 24 lines · Viresh Kumar
Quoted 23 lines · Emilio López

As uninitialized array members will be initialized to zero, we can avoid using a for loop by setting a value to it.

---
Note that I don't own any device using this driver, it has only been compile tested, but it shouldn't cause any issues.

 drivers/cpufreq/highbank-cpufreq.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/cpufreq/highbank-cpufreq.c +1 -2
index 66e3a71..30d4ae1 100644
@@ -28,13 +28,9 @@
 
 static int hb_voltage_change(unsigned int freq)
 {
-       int i;
-       u32 msg[HB_CPUFREQ_IPC_LEN];
+       u32 msg[HB_CPUFREQ_IPC_LEN] = {HB_CPUFREQ_CHANGE_NOTE};
 
Quoted 9 lines

drivers/cpufreq/highbank-cpufreq.c line 33

Quoted 2 lines
drivers/cpufreq/highbank-cpufreq.c +0 -1
-       msg[0] = HB_CPUFREQ_CHANGE_NOTE;
        msg[1] = freq / 1000000;

I think this can also be part of the definition of array, isn't it?

So it would be something like:

u32 msg[HB_CPUFREQ_IPC_LEN] = {HB_CPUFREQ_CHANGE_NOTE, freq / 1000000};

I incorrectly assumed that sparse would complain, but after testing I see it doesn't. Thanks for pointing it out, I'll send a v2 in a minute.

Emilio

#3 lore raw

PATCH v2 1/1 cpufreq: highbank: do not initialize array with a loop

In reply to Emilio López

As uninitialized array members will be initialized to zero, we can avoid using a for loop by setting a value to it.

---

Note that I don't own any device using this driver, it has only been compile tested, but it shouldn't cause any issues.

Changes v1 -> v2:
* Move freq / 1000000 to the array definition as suggested by Viresh Kumar

 drivers/cpufreq/highbank-cpufreq.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/cpufreq/highbank-cpufreq.c +1 -7
index 66e3a71..b61b5a3 100644
@@ -28,13 +28,7 @@
 
 static int hb_voltage_change(unsigned int freq)
 {
-	int i;
-	u32 msg[HB_CPUFREQ_IPC_LEN];
-
-	msg[0] = HB_CPUFREQ_CHANGE_NOTE;
-	msg[1] = freq / 1000000;
-	for (i = 2; i < HB_CPUFREQ_IPC_LEN; i++)
-		msg[i] = 0;
+	u32 msg[HB_CPUFREQ_IPC_LEN] = {HB_CPUFREQ_CHANGE_NOTE, freq / 1000000};
 
 	return pl320_ipc_transmit(msg);
 }
Signature · 1 line
1.8.2.rc0
maintainer Acked-by on v2 1/1
#4 lore raw
Quoted 21 lines · Emilio López

As uninitialized array members will be initialized to zero, we can avoid using a for loop by setting a value to it.

---

Note that I don't own any device using this driver, it has only been compile tested, but it shouldn't cause any issues.

Changes v1 -> v2:
* Move freq / 1000000 to the array definition as suggested by Viresh Kumar

 drivers/cpufreq/highbank-cpufreq.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/cpufreq/highbank-cpufreq.c +0 -0
index 66e3a71..b61b5a3 100644
@@ -28,13 +28,7 @@
 

drivers/cpufreq/highbank-cpufreq.c line 31

Quoted 10 lines
drivers/cpufreq/highbank-cpufreq.c +1 -7
 static int hb_voltage_change(unsigned int freq)
 {
-       int i;
-       u32 msg[HB_CPUFREQ_IPC_LEN];
-
-       msg[0] = HB_CPUFREQ_CHANGE_NOTE;
-       msg[1] = freq / 1000000;
-       for (i = 2; i < HB_CPUFREQ_IPC_LEN; i++)
-               msg[i] = 0;
+       u32 msg[HB_CPUFREQ_IPC_LEN] = {HB_CPUFREQ_CHANGE_NOTE, freq / 1000000};

If you haven't crossed 80 width:

Quoted 3 lines
drivers/cpufreq/highbank-cpufreq.c +0 -0
        return pl320_ipc_transmit(msg);
 }
Acked-by on v2 1/1
#5 lore raw
In reply to Emilio López
Quoted 25 lines · Emilio López

As uninitialized array members will be initialized to zero, we can avoid using a for loop by setting a value to it.

---

Note that I don't own any device using this driver, it has only been compile tested, but it shouldn't cause any issues.

Changes v1 -> v2:
* Move freq / 1000000 to the array definition as suggested by Viresh Kumar

 drivers/cpufreq/highbank-cpufreq.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/cpufreq/highbank-cpufreq.c +0 -1
index 66e3a71..b61b5a3 100644
@@ -28,13 +28,7 @@
 
 static int hb_voltage_change(unsigned int freq)
 {
-	int i;

drivers/cpufreq/highbank-cpufreq.c line 34

Quoted 10 lines
drivers/cpufreq/highbank-cpufreq.c +1 -6
-	u32 msg[HB_CPUFREQ_IPC_LEN];
-
-	msg[0] = HB_CPUFREQ_CHANGE_NOTE;
-	msg[1] = freq / 1000000;
-	for (i = 2; i < HB_CPUFREQ_IPC_LEN; i++)
-		msg[i] = 0;
+	u32 msg[HB_CPUFREQ_IPC_LEN] = {HB_CPUFREQ_CHANGE_NOTE, freq / 1000000};
 
 	return pl320_ipc_transmit(msg);
 }

Thanks for the improvement.

--Mark Langsdorf
Calxeda, Inc.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel