Commit 26ca8694344af4c833d22590c5b77d6b9cff0722

Authored by Viresh Kumar
Committed by Rafael J. Wysocki
1 parent 8a61e12e84

cpufreq: check cpufreq driver is valid and cpufreq isn't disabled in cpufreq_get()

cpufreq_get() can be called from external drivers which might not be aware if
cpufreq driver is registered or not. And so we should actually check if cpufreq
driver is registered or not and also if cpufreq is active or disabled, at the
beginning of cpufreq_get().

Otherwise call to lock_policy_rwsem_read() might hit BUG_ON(!policy).

Reported-and-tested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Showing 1 changed file with 3 additions and 0 deletions Side-by-side Diff

drivers/cpufreq/cpufreq.c
... ... @@ -1460,6 +1460,9 @@
1460 1460 {
1461 1461 unsigned int ret_freq = 0;
1462 1462  
  1463 + if (cpufreq_disabled() || !cpufreq_driver)
  1464 + return -ENOENT;
  1465 +
1463 1466 if (!down_read_trylock(&cpufreq_rwsem))
1464 1467 return 0;
1465 1468