aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/thermal/cpu_cooling.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 9ce0e9eef923..d1f9e1563ac6 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -652,31 +652,39 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
652 unsigned long state, u32 *power) 652 unsigned long state, u32 *power)
653{ 653{
654 unsigned int freq, num_cpus; 654 unsigned int freq, num_cpus;
655 cpumask_t cpumask; 655 cpumask_var_t cpumask;
656 u32 static_power, dynamic_power; 656 u32 static_power, dynamic_power;
657 int ret; 657 int ret;
658 struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; 658 struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
659 659
660 cpumask_and(&cpumask, &cpufreq_device->allowed_cpus, cpu_online_mask); 660 if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
661 num_cpus = cpumask_weight(&cpumask); 661 return -ENOMEM;
662
663 cpumask_and(cpumask, &cpufreq_device->allowed_cpus, cpu_online_mask);
664 num_cpus = cpumask_weight(cpumask);
662 665
663 /* None of our cpus are online, so no power */ 666 /* None of our cpus are online, so no power */
664 if (num_cpus == 0) { 667 if (num_cpus == 0) {
665 *power = 0; 668 *power = 0;
666 return 0; 669 ret = 0;
670 goto out;
667 } 671 }
668 672
669 freq = cpufreq_device->freq_table[state]; 673 freq = cpufreq_device->freq_table[state];
670 if (!freq) 674 if (!freq) {
671 return -EINVAL; 675 ret = -EINVAL;
676 goto out;
677 }
672 678
673 dynamic_power = cpu_freq_to_power(cpufreq_device, freq) * num_cpus; 679 dynamic_power = cpu_freq_to_power(cpufreq_device, freq) * num_cpus;
674 ret = get_static_power(cpufreq_device, tz, freq, &static_power); 680 ret = get_static_power(cpufreq_device, tz, freq, &static_power);
675 if (ret) 681 if (ret)
676 return ret; 682 goto out;
677 683
678 *power = static_power + dynamic_power; 684 *power = static_power + dynamic_power;
679 return 0; 685out:
686 free_cpumask_var(cpumask);
687 return ret;
680} 688}
681 689
682/** 690/**
@@ -802,16 +810,20 @@ __cpufreq_cooling_register(struct device_node *np,
802 struct cpufreq_cooling_device *cpufreq_dev; 810 struct cpufreq_cooling_device *cpufreq_dev;
803 char dev_name[THERMAL_NAME_LENGTH]; 811 char dev_name[THERMAL_NAME_LENGTH];
804 struct cpufreq_frequency_table *pos, *table; 812 struct cpufreq_frequency_table *pos, *table;
805 struct cpumask temp_mask; 813 cpumask_var_t temp_mask;
806 unsigned int freq, i, num_cpus; 814 unsigned int freq, i, num_cpus;
807 int ret; 815 int ret;
808 struct thermal_cooling_device_ops *cooling_ops; 816 struct thermal_cooling_device_ops *cooling_ops;
809 817
810 cpumask_and(&temp_mask, clip_cpus, cpu_online_mask); 818 if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
811 policy = cpufreq_cpu_get(cpumask_first(&temp_mask)); 819 return ERR_PTR(-ENOMEM);
820
821 cpumask_and(temp_mask, clip_cpus, cpu_online_mask);
822 policy = cpufreq_cpu_get(cpumask_first(temp_mask));
812 if (!policy) { 823 if (!policy) {
813 pr_debug("%s: CPUFreq policy not found\n", __func__); 824 pr_debug("%s: CPUFreq policy not found\n", __func__);
814 return ERR_PTR(-EPROBE_DEFER); 825 cool_dev = ERR_PTR(-EPROBE_DEFER);
826 goto free_cpumask;
815 } 827 }
816 828
817 table = policy->freq_table; 829 table = policy->freq_table;
@@ -931,7 +943,8 @@ free_cdev:
931 kfree(cpufreq_dev); 943 kfree(cpufreq_dev);
932put_policy: 944put_policy:
933 cpufreq_cpu_put(policy); 945 cpufreq_cpu_put(policy);
934 946free_cpumask:
947 free_cpumask_var(temp_mask);
935 return cool_dev; 948 return cool_dev;
936} 949}
937 950