linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] intel_idle: avoid theoretical uninitialized data usage
@ 2016-10-24 15:52 Arnd Bergmann
  2016-11-14  0:29 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2016-10-24 15:52 UTC (permalink / raw)
  To: Andy Henroid; +Cc: Arnd Bergmann, linux-pm, linux-kernel

When CONFIG_PCI is disabled, pci_read_config_byte() may not update
its result, as indicated by this warning:

drivers/idle/i7300_idle.c: In function ‘i7300_idle_notifier’:
drivers/idle/i7300_idle.c:423:141: warning: ‘got_ctl’ may be used uninitialized in this function [-Wmaybe-uninitialized]
drivers/idle/i7300_idle.c:415:5: note: ‘got_ctl’ was declared here

We know the function is never called if CONFIG_PCI is not set, so
this is harmless, but we can avoid the problem by checking the
return value of the config space accessor before using the result.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/idle/i7300_idle.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/idle/i7300_idle.c b/drivers/idle/i7300_idle.c
index ffeebc7e9f1c..9a104e558c77 100644
--- a/drivers/idle/i7300_idle.c
+++ b/drivers/idle/i7300_idle.c
@@ -347,6 +347,7 @@ static int i7300_idle_thrt_save(void)
 {
 	u32 new_mc_val;
 	u8 gblactlm;
+	int ret;
 
 	pci_read_config_byte(fbd_dev, DIMM_THRTCTL, &i7300_idle_thrtctl_saved);
 	pci_read_config_byte(fbd_dev, DIMM_THRTLOW, &i7300_idle_thrtlow_saved);
@@ -364,7 +365,9 @@ static int i7300_idle_thrt_save(void)
 	 * unlimited-activations while in open-loop throttling (i.e., when
 	 * Global Activation Throttle Limit is zero).
 	 */
-	pci_read_config_byte(fbd_dev, DIMM_GBLACT, &gblactlm);
+	ret = pci_read_config_byte(fbd_dev, DIMM_GBLACT, &gblactlm);
+	if (ret)
+		return ret;
 	dprintk("thrtctl_saved = 0x%02x, thrtlow_saved = 0x%02x\n",
 		i7300_idle_thrtctl_saved,
 		i7300_idle_thrtlow_saved);
@@ -413,14 +416,16 @@ static void i7300_idle_stop(void)
 {
 	u8 new_ctl;
 	u8 got_ctl;
+	int ret;
 
 	new_ctl = i7300_idle_thrtctl_saved & ~DIMM_THRTCTL_THRMHUNT;
 	pci_write_config_byte(fbd_dev, DIMM_THRTCTL, new_ctl);
 
 	pci_write_config_byte(fbd_dev, DIMM_THRTLOW, i7300_idle_thrtlow_saved);
 	pci_write_config_byte(fbd_dev, DIMM_THRTCTL, i7300_idle_thrtctl_saved);
-	pci_read_config_byte(fbd_dev, DIMM_THRTCTL, &got_ctl);
-	WARN_ON_ONCE(got_ctl != i7300_idle_thrtctl_saved);
+	ret = pci_read_config_byte(fbd_dev, DIMM_THRTCTL, &got_ctl);
+
+	WARN_ON_ONCE(ret || (got_ctl != i7300_idle_thrtctl_saved));
 }
 
 
-- 
2.9.0

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

* Re: [PATCH] intel_idle: avoid theoretical uninitialized data usage
  2016-10-24 15:52 [PATCH] intel_idle: avoid theoretical uninitialized data usage Arnd Bergmann
@ 2016-11-14  0:29 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2016-11-14  0:29 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: Andy Henroid, linux-pm, linux-kernel

On Monday, October 24, 2016 05:52:37 PM Arnd Bergmann wrote:
> When CONFIG_PCI is disabled, pci_read_config_byte() may not update
> its result, as indicated by this warning:
> 
> drivers/idle/i7300_idle.c: In function ‘i7300_idle_notifier’:
> drivers/idle/i7300_idle.c:423:141: warning: ‘got_ctl’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> drivers/idle/i7300_idle.c:415:5: note: ‘got_ctl’ was declared here
> 
> We know the function is never called if CONFIG_PCI is not set, so
> this is harmless, but we can avoid the problem by checking the
> return value of the config space accessor before using the result.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/idle/i7300_idle.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/idle/i7300_idle.c b/drivers/idle/i7300_idle.c
> index ffeebc7e9f1c..9a104e558c77 100644
> --- a/drivers/idle/i7300_idle.c
> +++ b/drivers/idle/i7300_idle.c
> @@ -347,6 +347,7 @@ static int i7300_idle_thrt_save(void)
>  {
>  	u32 new_mc_val;
>  	u8 gblactlm;
> +	int ret;
>  
>  	pci_read_config_byte(fbd_dev, DIMM_THRTCTL, &i7300_idle_thrtctl_saved);
>  	pci_read_config_byte(fbd_dev, DIMM_THRTLOW, &i7300_idle_thrtlow_saved);
> @@ -364,7 +365,9 @@ static int i7300_idle_thrt_save(void)
>  	 * unlimited-activations while in open-loop throttling (i.e., when
>  	 * Global Activation Throttle Limit is zero).
>  	 */
> -	pci_read_config_byte(fbd_dev, DIMM_GBLACT, &gblactlm);
> +	ret = pci_read_config_byte(fbd_dev, DIMM_GBLACT, &gblactlm);
> +	if (ret)
> +		return ret;
>  	dprintk("thrtctl_saved = 0x%02x, thrtlow_saved = 0x%02x\n",
>  		i7300_idle_thrtctl_saved,
>  		i7300_idle_thrtlow_saved);
> @@ -413,14 +416,16 @@ static void i7300_idle_stop(void)
>  {
>  	u8 new_ctl;
>  	u8 got_ctl;
> +	int ret;
>  
>  	new_ctl = i7300_idle_thrtctl_saved & ~DIMM_THRTCTL_THRMHUNT;
>  	pci_write_config_byte(fbd_dev, DIMM_THRTCTL, new_ctl);
>  
>  	pci_write_config_byte(fbd_dev, DIMM_THRTLOW, i7300_idle_thrtlow_saved);
>  	pci_write_config_byte(fbd_dev, DIMM_THRTCTL, i7300_idle_thrtctl_saved);
> -	pci_read_config_byte(fbd_dev, DIMM_THRTCTL, &got_ctl);
> -	WARN_ON_ONCE(got_ctl != i7300_idle_thrtctl_saved);
> +	ret = pci_read_config_byte(fbd_dev, DIMM_THRTCTL, &got_ctl);
> +
> +	WARN_ON_ONCE(ret || (got_ctl != i7300_idle_thrtctl_saved));
>  }
>  

Applied (with a minor subject tweak).

Thanks,
Rafael

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

end of thread, other threads:[~2016-11-14  0:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-24 15:52 [PATCH] intel_idle: avoid theoretical uninitialized data usage Arnd Bergmann
2016-11-14  0:29 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).