diff mbox series

[08/13] cpufreq: acpi-cpufreq: Take 'dummy' principle one stage further

Message ID 20200714145049.2496163-9-lee.jones@linaro.org
State New
Headers show
Series Rid W=1 warnings in CPUFreq | expand

Commit Message

Lee Jones July 14, 2020, 2:50 p.m. UTC
If we fail to use a variable, even a 'dummy' one, then the compiler
complains that it is set but not used.  We know this is fine, so we
set it to its own value here.

Fixes the following W=1 kernel build warning(s):

 drivers/cpufreq/acpi-cpufreq.c: In function ‘cpu_freq_read_intel’:
 drivers/cpufreq/acpi-cpufreq.c:247:11: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]
 drivers/cpufreq/acpi-cpufreq.c: In function ‘cpu_freq_read_amd’:
 drivers/cpufreq/acpi-cpufreq.c:265:11: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]

Cc: Andy Grover <andrew.grover@intel.com>
Cc: Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
Cc: Dominik Brodowski <linux@brodo.de>
Cc: Denis Sadykov <denis.m.sadykov@intel.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

---
 drivers/cpufreq/acpi-cpufreq.c | 2 ++
 1 file changed, 2 insertions(+)

-- 
2.25.1

Comments

Rafael J. Wysocki July 14, 2020, 4:03 p.m. UTC | #1
On Tue, Jul 14, 2020 at 4:51 PM Lee Jones <lee.jones@linaro.org> wrote:
>

> If we fail to use a variable, even a 'dummy' one, then the compiler

> complains that it is set but not used.  We know this is fine, so we

> set it to its own value here.


Which is kind of ugly in my personal view.  I hope that the compiler
will actually optimize the extra code away ...

> Fixes the following W=1 kernel build warning(s):


Well, "Makes the following ... warning(s) go away:" rather ...

>  drivers/cpufreq/acpi-cpufreq.c: In function ‘cpu_freq_read_intel’:

>  drivers/cpufreq/acpi-cpufreq.c:247:11: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]

>  drivers/cpufreq/acpi-cpufreq.c: In function ‘cpu_freq_read_amd’:

>  drivers/cpufreq/acpi-cpufreq.c:265:11: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]

>

> Cc: Andy Grover <andrew.grover@intel.com>

> Cc: Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>

> Cc: Dominik Brodowski <linux@brodo.de>

> Cc: Denis Sadykov <denis.m.sadykov@intel.com>

> Signed-off-by: Lee Jones <lee.jones@linaro.org>

> ---

>  drivers/cpufreq/acpi-cpufreq.c | 2 ++

>  1 file changed, 2 insertions(+)

>

> diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c

> index 429e5a36c08a9..d38a693b48e03 100644

> --- a/drivers/cpufreq/acpi-cpufreq.c

> +++ b/drivers/cpufreq/acpi-cpufreq.c

> @@ -247,6 +247,7 @@ static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)

>         u32 val, dummy;

>

>         rdmsr(MSR_IA32_PERF_CTL, val, dummy);

> +       dummy &= dummy; /* Silence set but not used warning */

>         return val;

>  }

>

> @@ -264,6 +265,7 @@ static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)

>         u32 val, dummy;

>

>         rdmsr(MSR_AMD_PERF_CTL, val, dummy);

> +       dummy &= dummy; /* Silence set but not used warning */

>         return val;

>  }

>

> --

> 2.25.1

>
Robin Murphy July 14, 2020, 4:20 p.m. UTC | #2
On 2020-07-14 17:03, Rafael J. Wysocki wrote:
> On Tue, Jul 14, 2020 at 4:51 PM Lee Jones <lee.jones@linaro.org> wrote:

>>

>> If we fail to use a variable, even a 'dummy' one, then the compiler

>> complains that it is set but not used.  We know this is fine, so we

>> set it to its own value here.

> 

> Which is kind of ugly in my personal view.  I hope that the compiler

> will actually optimize the extra code away ...

> 

>> Fixes the following W=1 kernel build warning(s):

> 

> Well, "Makes the following ... warning(s) go away:" rather ...


Isn't that what we have __maybe_unused and __always_unused for?

Robin.

>>   drivers/cpufreq/acpi-cpufreq.c: In function ‘cpu_freq_read_intel’:

>>   drivers/cpufreq/acpi-cpufreq.c:247:11: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]

>>   drivers/cpufreq/acpi-cpufreq.c: In function ‘cpu_freq_read_amd’:

>>   drivers/cpufreq/acpi-cpufreq.c:265:11: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]

>>

>> Cc: Andy Grover <andrew.grover@intel.com>

>> Cc: Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>

>> Cc: Dominik Brodowski <linux@brodo.de>

>> Cc: Denis Sadykov <denis.m.sadykov@intel.com>

>> Signed-off-by: Lee Jones <lee.jones@linaro.org>

>> ---

>>   drivers/cpufreq/acpi-cpufreq.c | 2 ++

>>   1 file changed, 2 insertions(+)

>>

>> diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c

>> index 429e5a36c08a9..d38a693b48e03 100644

>> --- a/drivers/cpufreq/acpi-cpufreq.c

>> +++ b/drivers/cpufreq/acpi-cpufreq.c

>> @@ -247,6 +247,7 @@ static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)

>>          u32 val, dummy;

>>

>>          rdmsr(MSR_IA32_PERF_CTL, val, dummy);

>> +       dummy &= dummy; /* Silence set but not used warning */

>>          return val;

>>   }

>>

>> @@ -264,6 +265,7 @@ static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)

>>          u32 val, dummy;

>>

>>          rdmsr(MSR_AMD_PERF_CTL, val, dummy);

>> +       dummy &= dummy; /* Silence set but not used warning */

>>          return val;

>>   }

>>

>> --

>> 2.25.1

>>

> 

> _______________________________________________

> linux-arm-kernel mailing list

> linux-arm-kernel@lists.infradead.org

> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

>
Lee Jones July 14, 2020, 9 p.m. UTC | #3
On Tue, 14 Jul 2020, Robin Murphy wrote:

> On 2020-07-14 17:03, Rafael J. Wysocki wrote:

> > On Tue, Jul 14, 2020 at 4:51 PM Lee Jones <lee.jones@linaro.org> wrote:

> > > 

> > > If we fail to use a variable, even a 'dummy' one, then the compiler

> > > complains that it is set but not used.  We know this is fine, so we

> > > set it to its own value here.

> > 

> > Which is kind of ugly in my personal view.  I hope that the compiler

> > will actually optimize the extra code away ...

> > 

> > > Fixes the following W=1 kernel build warning(s):

> > 

> > Well, "Makes the following ... warning(s) go away:" rather ...

> 

> Isn't that what we have __maybe_unused and __always_unused for?


Yes, that would be better.

I didn't know you could do that with standard variables.

Will fix.

> > >   drivers/cpufreq/acpi-cpufreq.c: In function ‘cpu_freq_read_intel’:

> > >   drivers/cpufreq/acpi-cpufreq.c:247:11: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]

> > >   drivers/cpufreq/acpi-cpufreq.c: In function ‘cpu_freq_read_amd’:

> > >   drivers/cpufreq/acpi-cpufreq.c:265:11: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]

> > > 

> > > Cc: Andy Grover <andrew.grover@intel.com>

> > > Cc: Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>

> > > Cc: Dominik Brodowski <linux@brodo.de>

> > > Cc: Denis Sadykov <denis.m.sadykov@intel.com>

> > > Signed-off-by: Lee Jones <lee.jones@linaro.org>

> > > ---

> > >   drivers/cpufreq/acpi-cpufreq.c | 2 ++

> > >   1 file changed, 2 insertions(+)

> > > 

> > > diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c

> > > index 429e5a36c08a9..d38a693b48e03 100644

> > > --- a/drivers/cpufreq/acpi-cpufreq.c

> > > +++ b/drivers/cpufreq/acpi-cpufreq.c

> > > @@ -247,6 +247,7 @@ static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)

> > >          u32 val, dummy;

> > > 

> > >          rdmsr(MSR_IA32_PERF_CTL, val, dummy);

> > > +       dummy &= dummy; /* Silence set but not used warning */

> > >          return val;

> > >   }

> > > 

> > > @@ -264,6 +265,7 @@ static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)

> > >          u32 val, dummy;

> > > 

> > >          rdmsr(MSR_AMD_PERF_CTL, val, dummy);

> > > +       dummy &= dummy; /* Silence set but not used warning */

> > >          return val;

> > >   }

> > > 

> > 

> > _______________________________________________

> > linux-arm-kernel mailing list

> > linux-arm-kernel@lists.infradead.org

> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

> > 


-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
diff mbox series

Patch

diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 429e5a36c08a9..d38a693b48e03 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -247,6 +247,7 @@  static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)
 	u32 val, dummy;
 
 	rdmsr(MSR_IA32_PERF_CTL, val, dummy);
+	dummy &= dummy; /* Silence set but not used warning */
 	return val;
 }
 
@@ -264,6 +265,7 @@  static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)
 	u32 val, dummy;
 
 	rdmsr(MSR_AMD_PERF_CTL, val, dummy);
+	dummy &= dummy; /* Silence set but not used warning */
 	return val;
 }