linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpufreq: Lock CPU online/offline in cpufreq_register_driver()
@ 2015-07-29 23:45 Rafael J. Wysocki
  2015-07-30  5:48 ` Viresh Kumar
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2015-07-29 23:45 UTC (permalink / raw)
  To: Linux PM list; +Cc: Linux Kernel Mailing List, Viresh Kumar, Russell King

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

To protect against races with concurrent CPU online/offline, call
get_online_cpus() before registering a cpufreq driver.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq.c
+++ linux-pm/drivers/cpufreq/cpufreq.c
@@ -2471,10 +2471,14 @@ int cpufreq_register_driver(struct cpufr
 
 	pr_debug("trying to register driver %s\n", driver_data->name);
 
+	/* Protect against concurrent CPU online/offline. */
+	get_online_cpus();
+
 	write_lock_irqsave(&cpufreq_driver_lock, flags);
 	if (cpufreq_driver) {
 		write_unlock_irqrestore(&cpufreq_driver_lock, flags);
-		return -EEXIST;
+		ret = -EEXIST;
+		goto out;
 	}
 	cpufreq_driver = driver_data;
 	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
@@ -2513,7 +2517,10 @@ int cpufreq_register_driver(struct cpufr
 	register_hotcpu_notifier(&cpufreq_cpu_notifier);
 	pr_debug("driver %s up and running\n", driver_data->name);
 
-	return 0;
+out:
+	put_online_cpus();
+	return ret;
+
 err_if_unreg:
 	subsys_interface_unregister(&cpufreq_interface);
 err_boost_unreg:
@@ -2523,7 +2530,7 @@ err_null_driver:
 	write_lock_irqsave(&cpufreq_driver_lock, flags);
 	cpufreq_driver = NULL;
 	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
-	return ret;
+	goto out;
 }
 EXPORT_SYMBOL_GPL(cpufreq_register_driver);
 


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

* Re: [PATCH] cpufreq: Lock CPU online/offline in cpufreq_register_driver()
  2015-07-29 23:45 [PATCH] cpufreq: Lock CPU online/offline in cpufreq_register_driver() Rafael J. Wysocki
@ 2015-07-30  5:48 ` Viresh Kumar
  2015-07-30  7:12   ` Viresh Kumar
  0 siblings, 1 reply; 3+ messages in thread
From: Viresh Kumar @ 2015-07-30  5:48 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Linux PM list, Linux Kernel Mailing List, Russell King

On 30-07-15, 01:45, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> To protect against races with concurrent CPU online/offline, call
> get_online_cpus() before registering a cpufreq driver.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpufreq/cpufreq.c |   13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> Index: linux-pm/drivers/cpufreq/cpufreq.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq.c
> +++ linux-pm/drivers/cpufreq/cpufreq.c
> @@ -2471,10 +2471,14 @@ int cpufreq_register_driver(struct cpufr
>  
>  	pr_debug("trying to register driver %s\n", driver_data->name);
>  
> +	/* Protect against concurrent CPU online/offline. */
> +	get_online_cpus();
> +
>  	write_lock_irqsave(&cpufreq_driver_lock, flags);
>  	if (cpufreq_driver) {
>  		write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> -		return -EEXIST;
> +		ret = -EEXIST;
> +		goto out;
>  	}
>  	cpufreq_driver = driver_data;
>  	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> @@ -2513,7 +2517,10 @@ int cpufreq_register_driver(struct cpufr
>  	register_hotcpu_notifier(&cpufreq_cpu_notifier);
>  	pr_debug("driver %s up and running\n", driver_data->name);
>  
> -	return 0;
> +out:
> +	put_online_cpus();
> +	return ret;
> +
>  err_if_unreg:
>  	subsys_interface_unregister(&cpufreq_interface);
>  err_boost_unreg:
> @@ -2523,7 +2530,7 @@ err_null_driver:
>  	write_lock_irqsave(&cpufreq_driver_lock, flags);
>  	cpufreq_driver = NULL;
>  	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> -	return ret;
> +	goto out;
>  }
>  EXPORT_SYMBOL_GPL(cpufreq_register_driver);

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH] cpufreq: Lock CPU online/offline in cpufreq_register_driver()
  2015-07-30  5:48 ` Viresh Kumar
@ 2015-07-30  7:12   ` Viresh Kumar
  0 siblings, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2015-07-30  7:12 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Linux PM list, Linux Kernel Mailing List, Russell King

Fixing Russell's id.

On 30-07-15, 11:18, Viresh Kumar wrote:
> On 30-07-15, 01:45, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > 
> > To protect against races with concurrent CPU online/offline, call
> > get_online_cpus() before registering a cpufreq driver.
> > 
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> >  drivers/cpufreq/cpufreq.c |   13 ++++++++++---
> >  1 file changed, 10 insertions(+), 3 deletions(-)
> > 
> > Index: linux-pm/drivers/cpufreq/cpufreq.c
> > ===================================================================
> > --- linux-pm.orig/drivers/cpufreq/cpufreq.c
> > +++ linux-pm/drivers/cpufreq/cpufreq.c
> > @@ -2471,10 +2471,14 @@ int cpufreq_register_driver(struct cpufr
> >  
> >  	pr_debug("trying to register driver %s\n", driver_data->name);
> >  
> > +	/* Protect against concurrent CPU online/offline. */
> > +	get_online_cpus();
> > +
> >  	write_lock_irqsave(&cpufreq_driver_lock, flags);
> >  	if (cpufreq_driver) {
> >  		write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> > -		return -EEXIST;
> > +		ret = -EEXIST;
> > +		goto out;
> >  	}
> >  	cpufreq_driver = driver_data;
> >  	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> > @@ -2513,7 +2517,10 @@ int cpufreq_register_driver(struct cpufr
> >  	register_hotcpu_notifier(&cpufreq_cpu_notifier);
> >  	pr_debug("driver %s up and running\n", driver_data->name);
> >  
> > -	return 0;
> > +out:
> > +	put_online_cpus();
> > +	return ret;
> > +
> >  err_if_unreg:
> >  	subsys_interface_unregister(&cpufreq_interface);
> >  err_boost_unreg:
> > @@ -2523,7 +2530,7 @@ err_null_driver:
> >  	write_lock_irqsave(&cpufreq_driver_lock, flags);
> >  	cpufreq_driver = NULL;
> >  	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> > -	return ret;
> > +	goto out;
> >  }
> >  EXPORT_SYMBOL_GPL(cpufreq_register_driver);
> 
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
> 
> -- 
> viresh

-- 
viresh

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

end of thread, other threads:[~2015-07-30  7:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-29 23:45 [PATCH] cpufreq: Lock CPU online/offline in cpufreq_register_driver() Rafael J. Wysocki
2015-07-30  5:48 ` Viresh Kumar
2015-07-30  7:12   ` Viresh Kumar

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).