Skip to contentSkip to conversation

cpufreq: spear: Fix uninitialized variable "i"

PATCH In review Rob Herring (Arm) 2 participants 4 messages Aug 5, 2024 – Aug 7, 2024 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: spear: Fix uninitialized variable "i"

The refactoring in commit dca2ef2b7d91 ("cpufreq: spear: Use of_property_for_each_u32() instead of open coding") left "i" uninitialized. Initialize it to 0.

Note that gcc doesn't detect this, only clang does.

Fixes dca2ef2b7d91 ("cpufreq: spear: Use of_property_for_each_u32() instead of open coding")
---
 drivers/cpufreq/spear-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/spear-cpufreq.c +1 -1
index 4d28147c23f1..f8c16699a68d 100644
@@ -173,7 +173,7 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
 	struct device_node *np;
 	struct cpufreq_frequency_table *freq_tbl;
 	u32 val;
-	int cnt, i, ret;
+	int cnt, i = 0, ret;
 
 	np = of_cpu_device_node_get(0);
 	if (!np) {
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 19 lines · Rob Herring (Arm)

The refactoring in commit dca2ef2b7d91 ("cpufreq: spear: Use of_property_for_each_u32() instead of open coding") left "i" uninitialized. Initialize it to 0.

Note that gcc doesn't detect this, only clang does.

Fixes dca2ef2b7d91 ("cpufreq: spear: Use of_property_for_each_u32() instead of open coding")
---
 drivers/cpufreq/spear-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/spear-cpufreq.c +0 -0
index 4d28147c23f1..f8c16699a68d 100644

drivers/cpufreq/spear-cpufreq.c static int spear_cpufreq_probe(struct platform_device *pdev) · line 176

Quoted 5 lines
drivers/cpufreq/spear-cpufreq.c +1 -1
@@ -173,7 +173,7 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
 	struct device_node *np;
 	struct cpufreq_frequency_table *freq_tbl;
 	u32 val;
-	int cnt, i, ret;
+	int cnt, i = 0, ret;

We don't increment 'i' anymore, don't we need an i++ in:

        freq_tbl[i].frequency = val;

?

Signature · 1 line
viresh
#2 lore raw
Quoted 29 lines · Viresh Kumar
Quoted 19 lines · Rob Herring (Arm)

The refactoring in commit dca2ef2b7d91 ("cpufreq: spear: Use of_property_for_each_u32() instead of open coding") left "i" uninitialized. Initialize it to 0.

Note that gcc doesn't detect this, only clang does.

Fixes dca2ef2b7d91 ("cpufreq: spear: Use of_property_for_each_u32() instead of open coding")
---
 drivers/cpufreq/spear-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/spear-cpufreq.c +0 -0
index 4d28147c23f1..f8c16699a68d 100644

drivers/cpufreq/spear-cpufreq.c static int spear_cpufreq_probe(struct platform_device *pdev) · line 176

Quoted 5 lines
drivers/cpufreq/spear-cpufreq.c +1 -1
@@ -173,7 +173,7 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
      struct device_node *np;
      struct cpufreq_frequency_table *freq_tbl;
      u32 val;
-     int cnt, i, ret;
+     int cnt, i = 0, ret;

We don't increment 'i' anymore, don't we need an i++ in:

Quoted 3 lines
        freq_tbl[i].frequency = val;

?

Sigh. Yes.

Rob

maintainer
#3 lore raw
Quoted 8 lines · Rob Herring
Quoted 5 lines · Viresh Kumar

We don't increment 'i' anymore, don't we need an i++ in:

        freq_tbl[i].frequency = val;

?

Sigh. Yes.

Fixed the original commit with this, hope this doesn't add any new bugs:

drivers/cpufreq/spear-cpufreq.c +2 -2
index 777f7f5b3671..d8ab5b01d46d 100644
@@ -173,7 +173,7 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
        struct device_node *np;
        struct cpufreq_frequency_table *freq_tbl;
        u32 val;
-       int cnt, i, ret;
+       int cnt, ret, i = 0;
 
        np = of_cpu_device_node_get(0);
        if (!np) {
@@ -199,7 +199,7 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
        }
 
        of_property_for_each_u32(np, "cpufreq_tbl", val)
-               freq_tbl[i].frequency = val;
+               freq_tbl[i++].frequency = val;
 
        freq_tbl[cnt].frequency = CPUFREQ_TABLE_END;
 
Signature · 1 line
viresh