public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq: spear: Fix uninitialized variable "i"
@ 2024-08-05 20:20 Rob Herring (Arm)
  2024-08-06  4:49 ` Viresh Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Rob Herring (Arm) @ 2024-08-05 20:20 UTC (permalink / raw)
  To: Rafael J. Wysocki, Viresh Kumar, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt
  Cc: kernel test robot, linux-pm, linux-kernel, llvm

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")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202408030418.gnJDcCpm-lkp@intel.com/
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
---
 drivers/cpufreq/spear-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/spear-cpufreq.c b/drivers/cpufreq/spear-cpufreq.c
index 4d28147c23f1..f8c16699a68d 100644
--- a/drivers/cpufreq/spear-cpufreq.c
+++ b/drivers/cpufreq/spear-cpufreq.c
@@ -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) {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpufreq: spear: Fix uninitialized variable "i"
  2024-08-05 20:20 [PATCH] cpufreq: spear: Fix uninitialized variable "i" Rob Herring (Arm)
@ 2024-08-06  4:49 ` Viresh Kumar
  2024-08-06 16:08   ` Rob Herring
  0 siblings, 1 reply; 4+ messages in thread
From: Viresh Kumar @ 2024-08-06  4:49 UTC (permalink / raw)
  To: Rob Herring (Arm)
  Cc: Rafael J. Wysocki, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, kernel test robot, linux-pm,
	linux-kernel, llvm

On 05-08-24, 14:20, Rob Herring (Arm) wrote:
> 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")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202408030418.gnJDcCpm-lkp@intel.com/
> Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
> ---
>  drivers/cpufreq/spear-cpufreq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/spear-cpufreq.c b/drivers/cpufreq/spear-cpufreq.c
> index 4d28147c23f1..f8c16699a68d 100644
> --- a/drivers/cpufreq/spear-cpufreq.c
> +++ b/drivers/cpufreq/spear-cpufreq.c
> @@ -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;

?

-- 
viresh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpufreq: spear: Fix uninitialized variable "i"
  2024-08-06  4:49 ` Viresh Kumar
@ 2024-08-06 16:08   ` Rob Herring
  2024-08-07  6:26     ` Viresh Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Rob Herring @ 2024-08-06 16:08 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, kernel test robot, linux-pm,
	linux-kernel, llvm

On Mon, Aug 5, 2024 at 10:49 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 05-08-24, 14:20, Rob Herring (Arm) wrote:
> > 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")
> > Reported-by: kernel test robot <lkp@intel.com>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202408030418.gnJDcCpm-lkp@intel.com/
> > Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
> > ---
> >  drivers/cpufreq/spear-cpufreq.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/cpufreq/spear-cpufreq.c b/drivers/cpufreq/spear-cpufreq.c
> > index 4d28147c23f1..f8c16699a68d 100644
> > --- a/drivers/cpufreq/spear-cpufreq.c
> > +++ b/drivers/cpufreq/spear-cpufreq.c
> > @@ -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;
>
> ?

Sigh. Yes.


Rob

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpufreq: spear: Fix uninitialized variable "i"
  2024-08-06 16:08   ` Rob Herring
@ 2024-08-07  6:26     ` Viresh Kumar
  0 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2024-08-07  6:26 UTC (permalink / raw)
  To: Rob Herring
  Cc: Rafael J. Wysocki, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, kernel test robot, linux-pm,
	linux-kernel, llvm

On 06-08-24, 10:08, Rob Herring wrote:
> On Mon, Aug 5, 2024 at 10:49 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > 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:

diff --git a/drivers/cpufreq/spear-cpufreq.c b/drivers/cpufreq/spear-cpufreq.c
index 777f7f5b3671..d8ab5b01d46d 100644
--- a/drivers/cpufreq/spear-cpufreq.c
+++ b/drivers/cpufreq/spear-cpufreq.c
@@ -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;

-- 
viresh

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-07  6:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-05 20:20 [PATCH] cpufreq: spear: Fix uninitialized variable "i" Rob Herring (Arm)
2024-08-06  4:49 ` Viresh Kumar
2024-08-06 16:08   ` Rob Herring
2024-08-07  6:26     ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox