diff mbox

intel_idle: Check cpu_idle_get_driver() for NULL before dereferencing it.

Message ID 1343918341-25985-1-git-send-email-konrad.wilk@oracle.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Konrad Rzeszutek Wilk Aug. 2, 2012, 2:39 p.m. UTC
If the machine is booted without any cpu_idle driver set
(b/c disable_cpuidle() has been called) we should follow
other users of cpu_idle API and check the return value
for NULL before using it.

Reported-by: Mark van Dijk <mark@internecto.net>
Tested-by: Mark van Dijk <mark@internecto.net>
Suggested-by: Jan Beulich <JBeulich@suse.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 drivers/idle/intel_idle.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Rafael Wysocki Aug. 4, 2012, 9:56 p.m. UTC | #1
On Thursday, August 02, 2012, Konrad Rzeszutek Wilk wrote:
> If the machine is booted without any cpu_idle driver set
> (b/c disable_cpuidle() has been called) we should follow
> other users of cpu_idle API and check the return value
> for NULL before using it.
> 
> Reported-by: Mark van Dijk <mark@internecto.net>
> Tested-by: Mark van Dijk <mark@internecto.net>
> Suggested-by: Jan Beulich <JBeulich@suse.com>
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> ---
>  drivers/idle/intel_idle.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
> index f559088..7383aa0 100644
> --- a/drivers/idle/intel_idle.c
> +++ b/drivers/idle/intel_idle.c
> @@ -607,7 +607,7 @@ static int __init intel_idle_init(void)
>  	retval = cpuidle_register_driver(&intel_idle_driver);
>  	if (retval) {

What about:

  		struct cpuidle_driver *drv = cpuidle_get_driver();

  		printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
			drv ? drv->name : "none");

>  		printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
> -			cpuidle_get_driver()->name);
> +			cpuidle_get_driver() ? cpuidle_get_driver()->name : "none");
>  		return retval;
>  	}
>  
> 

Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Konrad Rzeszutek Wilk Aug. 6, 2012, 2:33 p.m. UTC | #2
On Sat, Aug 04, 2012 at 11:56:35PM +0200, Rafael J. Wysocki wrote:
> On Thursday, August 02, 2012, Konrad Rzeszutek Wilk wrote:
> > If the machine is booted without any cpu_idle driver set
> > (b/c disable_cpuidle() has been called) we should follow
> > other users of cpu_idle API and check the return value
> > for NULL before using it.
> > 
> > Reported-by: Mark van Dijk <mark@internecto.net>
> > Tested-by: Mark van Dijk <mark@internecto.net>
> > Suggested-by: Jan Beulich <JBeulich@suse.com>
> > Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> > ---
> >  drivers/idle/intel_idle.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> > 
> > diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
> > index f559088..7383aa0 100644
> > --- a/drivers/idle/intel_idle.c
> > +++ b/drivers/idle/intel_idle.c
> > @@ -607,7 +607,7 @@ static int __init intel_idle_init(void)
> >  	retval = cpuidle_register_driver(&intel_idle_driver);
> >  	if (retval) {
> 
> What about:
> 
>   		struct cpuidle_driver *drv = cpuidle_get_driver();
> 
>   		printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
> 			drv ? drv->name : "none");

Much prettier. Let me spin that up.

> 
> >  		printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
> > -			cpuidle_get_driver()->name);
> > +			cpuidle_get_driver() ? cpuidle_get_driver()->name : "none");
> >  		return retval;
> >  	}
> >  
> > 
> 
> Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index f559088..7383aa0 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -607,7 +607,7 @@  static int __init intel_idle_init(void)
 	retval = cpuidle_register_driver(&intel_idle_driver);
 	if (retval) {
 		printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
-			cpuidle_get_driver()->name);
+			cpuidle_get_driver() ? cpuidle_get_driver()->name : "none");
 		return retval;
 	}