Patchwork cpufreq: highbank: do not initialize array with a loop

login
register
mail settings
Submitter Emilio López
Date Feb. 24, 2013, 5:01 p.m.
Message ID <1361725277-5125-1-git-send-email-emilio@elopez.com.ar>
Download mbox | patch
Permalink /patch/222775/
State New
Headers show

Comments

Emilio López - Feb. 24, 2013, 5:01 p.m.
As uninitialized array members will be initialized to zero, we can
avoid using a for loop by setting a value to it.

Signed-off-by: Emilio López <emilio@elopez.com.ar>
---
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(-)
viresh kumar - Feb. 25, 2013, 3:41 a.m.
On Sun, Feb 24, 2013 at 10:31 PM, Emilio López <emilio@elopez.com.ar> wrote:
> As uninitialized array members will be initialized to zero, we can
> avoid using a for loop by setting a value to it.
>
> Signed-off-by: Emilio López <emilio@elopez.com.ar>
> ---
> 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(-)
>
> diff --git a/drivers/cpufreq/highbank-cpufreq.c b/drivers/cpufreq/highbank-cpufreq.c
> index 66e3a71..30d4ae1 100644
> --- a/drivers/cpufreq/highbank-cpufreq.c
> +++ b/drivers/cpufreq/highbank-cpufreq.c
> @@ -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};

> -       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
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Emilio López - Feb. 25, 2013, 10:58 a.m.
Hello,

El 25/02/13 00:41, Viresh Kumar escribió:
> On Sun, Feb 24, 2013 at 10:31 PM, Emilio López <emilio@elopez.com.ar> wrote:
>> As uninitialized array members will be initialized to zero, we can
>> avoid using a for loop by setting a value to it.
>>
>> Signed-off-by: Emilio López <emilio@elopez.com.ar>
>> ---
>> 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(-)
>>
>> diff --git a/drivers/cpufreq/highbank-cpufreq.c b/drivers/cpufreq/highbank-cpufreq.c
>> index 66e3a71..30d4ae1 100644
>> --- a/drivers/cpufreq/highbank-cpufreq.c
>> +++ b/drivers/cpufreq/highbank-cpufreq.c
>> @@ -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};
> 

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

Patch

diff --git a/drivers/cpufreq/highbank-cpufreq.c b/drivers/cpufreq/highbank-cpufreq.c
index 66e3a71..30d4ae1 100644
--- a/drivers/cpufreq/highbank-cpufreq.c
+++ b/drivers/cpufreq/highbank-cpufreq.c
@@ -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);
 }