]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 1 Mar 2017 17:54:32 +0000 (09:54 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 1 Mar 2017 17:54:32 +0000 (09:54 -0800)
Pull thermal management updates from Zhang Rui:

 - add thermal driver for R-Car Gen3 thermal sensors.

 - add thermal driver for ZTE' zx2967 family thermal sensors.

 - convert thermal ID allocation from IDR to IDA.

 - fix a possible NULL dereference in imx thermal driver.

 - fix a ti-soc-thermal driver dependency issue so that critical thermal
   control is still available when CPU_THERMAL is not defined.

 - update binding information for QorIQ thermal driver.

 - a couple of cleanups in thermal core, intel_powerclamp, exynos,
   dra752-thermal, mtk-thermal driver.

* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux:
  powerpc/mpc85xx: Update TMU device tree node for T1023/T1024
  powerpc/mpc85xx: Update TMU device tree node for T1040/T1042
  dt-bindings: Update QorIQ TMU thermal bindings
  thermal: mtk_thermal: Staticise a number of data variables
  thermal: arm: dra752: Remove all TSHUT related definitions
  thermal: arm: dra752: Remove TSHUT configuration
  thermal: ti-soc-thermal: Remove CPU_THERMAL Dependency from TI_THERMAL
  thermal: imx: Fix possible NULL dereference.
  thermal: exynos: Remove parsing unused samsung,tmu_cal_mode property
  thermal: zx2967: add thermal driver for ZTE's zx2967 family
  thermal: use cpumask_var_t for on-stack cpu masks
  dt: bindings: add documentation for zx2967 family thermal sensor
  thermal/intel_powerclamp: Remove set-but-not-used variables
  thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver
  thermal: rcar_gen3_thermal: Document the R-Car Gen3
  thermal: convert devfreq_cooling to use an IDA
  thermal: convert cpu_cooling to use an IDA
  thermal: convert clock cooling to use an IDA
  thermal core: convert ID allocation to IDA

1  2 
drivers/thermal/cpu_cooling.c
drivers/thermal/devfreq_cooling.c

index 85fdbf762fa02ac4d70ed231a603afe23bb5013d,c6f33218b431a99b0310cd67260c59cad550ebb8..91048eeca28b2dc3d81f234ed60bbfdd796f8277
@@@ -26,6 -26,7 +26,7 @@@
  #include <linux/thermal.h>
  #include <linux/cpufreq.h>
  #include <linux/err.h>
+ #include <linux/idr.h>
  #include <linux/pm_opp.h>
  #include <linux/slab.h>
  #include <linux/cpu.h>
@@@ -104,50 -105,13 +105,13 @@@ struct cpufreq_cooling_device 
        struct device *cpu_dev;
        get_static_t plat_get_static_power;
  };
- static DEFINE_IDR(cpufreq_idr);
- static DEFINE_MUTEX(cooling_cpufreq_lock);
+ static DEFINE_IDA(cpufreq_ida);
  
  static unsigned int cpufreq_dev_count;
  
  static DEFINE_MUTEX(cooling_list_lock);
  static LIST_HEAD(cpufreq_dev_list);
  
- /**
-  * get_idr - function to get a unique id.
-  * @idr: struct idr * handle used to create a id.
-  * @id: int * value generated by this function.
-  *
-  * This function will populate @id with an unique
-  * id, using the idr API.
-  *
-  * Return: 0 on success, an error code on failure.
-  */
- static int get_idr(struct idr *idr, int *id)
- {
-       int ret;
-       mutex_lock(&cooling_cpufreq_lock);
-       ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL);
-       mutex_unlock(&cooling_cpufreq_lock);
-       if (unlikely(ret < 0))
-               return ret;
-       *id = ret;
-       return 0;
- }
- /**
-  * release_idr - function to free the unique id.
-  * @idr: struct idr * handle used for creating the id.
-  * @id: int value representing the unique id.
-  */
- static void release_idr(struct idr *idr, int id)
- {
-       mutex_lock(&cooling_cpufreq_lock);
-       idr_remove(idr, id);
-       mutex_unlock(&cooling_cpufreq_lock);
- }
  /* Below code defines functions to be used for cpufreq as cooling device */
  
  /**
@@@ -297,6 -261,8 +261,6 @@@ static int build_dyn_power_table(struc
        if (!power_table)
                return -ENOMEM;
  
 -      rcu_read_lock();
 -
        for (freq = 0, i = 0;
             opp = dev_pm_opp_find_freq_ceil(dev, &freq), !IS_ERR(opp);
             freq++, i++) {
                u64 power;
  
                if (i >= num_opps) {
 -                      rcu_read_unlock();
                        ret = -EAGAIN;
                        goto free_power_table;
                }
  
                freq_mhz = freq / 1000000;
                voltage_mv = dev_pm_opp_get_voltage(opp) / 1000;
 +              dev_pm_opp_put(opp);
  
                /*
                 * Do the multiplication with MHz and millivolt so as
                power_table[i].power = power;
        }
  
 -      rcu_read_unlock();
 -
        if (i != num_opps) {
                ret = PTR_ERR(opp);
                goto free_power_table;
@@@ -429,10 -397,13 +393,10 @@@ static int get_static_power(struct cpuf
                return 0;
        }
  
 -      rcu_read_lock();
 -
        opp = dev_pm_opp_find_freq_exact(cpufreq_device->cpu_dev, freq_hz,
                                         true);
        voltage = dev_pm_opp_get_voltage(opp);
 -
 -      rcu_read_unlock();
 +      dev_pm_opp_put(opp);
  
        if (voltage == 0) {
                dev_warn_ratelimited(cpufreq_device->cpu_dev,
@@@ -645,31 -616,39 +609,39 @@@ static int cpufreq_state2power(struct t
                               unsigned long state, u32 *power)
  {
        unsigned int freq, num_cpus;
-       cpumask_t cpumask;
+       cpumask_var_t cpumask;
        u32 static_power, dynamic_power;
        int ret;
        struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
  
-       cpumask_and(&cpumask, &cpufreq_device->allowed_cpus, cpu_online_mask);
-       num_cpus = cpumask_weight(&cpumask);
+       if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
+               return -ENOMEM;
+       cpumask_and(cpumask, &cpufreq_device->allowed_cpus, cpu_online_mask);
+       num_cpus = cpumask_weight(cpumask);
  
        /* None of our cpus are online, so no power */
        if (num_cpus == 0) {
                *power = 0;
-               return 0;
+               ret = 0;
+               goto out;
        }
  
        freq = cpufreq_device->freq_table[state];
-       if (!freq)
-               return -EINVAL;
+       if (!freq) {
+               ret = -EINVAL;
+               goto out;
+       }
  
        dynamic_power = cpu_freq_to_power(cpufreq_device, freq) * num_cpus;
        ret = get_static_power(cpufreq_device, tz, freq, &static_power);
        if (ret)
-               return ret;
+               goto out;
  
        *power = static_power + dynamic_power;
-       return 0;
+ out:
+       free_cpumask_var(cpumask);
+       return ret;
  }
  
  /**
@@@ -795,16 -774,20 +767,20 @@@ __cpufreq_cooling_register(struct devic
        struct cpufreq_cooling_device *cpufreq_dev;
        char dev_name[THERMAL_NAME_LENGTH];
        struct cpufreq_frequency_table *pos, *table;
-       struct cpumask temp_mask;
+       cpumask_var_t temp_mask;
        unsigned int freq, i, num_cpus;
        int ret;
        struct thermal_cooling_device_ops *cooling_ops;
  
-       cpumask_and(&temp_mask, clip_cpus, cpu_online_mask);
-       policy = cpufreq_cpu_get(cpumask_first(&temp_mask));
+       if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
+               return ERR_PTR(-ENOMEM);
+       cpumask_and(temp_mask, clip_cpus, cpu_online_mask);
+       policy = cpufreq_cpu_get(cpumask_first(temp_mask));
        if (!policy) {
                pr_debug("%s: CPUFreq policy not found\n", __func__);
-               return ERR_PTR(-EPROBE_DEFER);
+               cool_dev = ERR_PTR(-EPROBE_DEFER);
+               goto free_cpumask;
        }
  
        table = policy->freq_table;
                cooling_ops = &cpufreq_cooling_ops;
        }
  
-       ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);
-       if (ret) {
+       ret = ida_simple_get(&cpufreq_ida, 0, 0, GFP_KERNEL);
+       if (ret < 0) {
                cool_dev = ERR_PTR(ret);
                goto free_power_table;
        }
+       cpufreq_dev->id = ret;
  
        /* Fill freq-table in descending order of frequencies */
        for (i = 0, freq = -1; i <= cpufreq_dev->max_level; i++) {
        cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev,
                                                      cooling_ops);
        if (IS_ERR(cool_dev))
-               goto remove_idr;
+               goto remove_ida;
  
        cpufreq_dev->clipped_freq = cpufreq_dev->freq_table[0];
        cpufreq_dev->cool_dev = cool_dev;
  
-       mutex_lock(&cooling_cpufreq_lock);
        mutex_lock(&cooling_list_lock);
        list_add(&cpufreq_dev->node, &cpufreq_dev_list);
-       mutex_unlock(&cooling_list_lock);
  
        /* Register the notifier for first cpufreq cooling device */
        if (!cpufreq_dev_count++)
                cpufreq_register_notifier(&thermal_cpufreq_notifier_block,
                                          CPUFREQ_POLICY_NOTIFIER);
-       mutex_unlock(&cooling_cpufreq_lock);
+       mutex_unlock(&cooling_list_lock);
  
        goto put_policy;
  
- remove_idr:
-       release_idr(&cpufreq_idr, cpufreq_dev->id);
+ remove_ida:
+       ida_simple_remove(&cpufreq_ida, cpufreq_dev->id);
  free_power_table:
        kfree(cpufreq_dev->dyn_power_table);
  free_table:
@@@ -924,7 -905,8 +898,8 @@@ free_cdev
        kfree(cpufreq_dev);
  put_policy:
        cpufreq_cpu_put(policy);
+ free_cpumask:
+       free_cpumask_var(temp_mask);
        return cool_dev;
  }
  
@@@ -1052,20 -1034,17 +1027,17 @@@ void cpufreq_cooling_unregister(struct 
  
        cpufreq_dev = cdev->devdata;
  
+       mutex_lock(&cooling_list_lock);
        /* Unregister the notifier for the last cpufreq cooling device */
-       mutex_lock(&cooling_cpufreq_lock);
        if (!--cpufreq_dev_count)
                cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block,
                                            CPUFREQ_POLICY_NOTIFIER);
  
-       mutex_lock(&cooling_list_lock);
        list_del(&cpufreq_dev->node);
        mutex_unlock(&cooling_list_lock);
  
-       mutex_unlock(&cooling_cpufreq_lock);
        thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
-       release_idr(&cpufreq_idr, cpufreq_dev->id);
+       ida_simple_remove(&cpufreq_ida, cpufreq_dev->id);
        kfree(cpufreq_dev->dyn_power_table);
        kfree(cpufreq_dev->time_in_idle_timestamp);
        kfree(cpufreq_dev->time_in_idle);
index ba7a5cd994dc9229351bd4ee057941afabcab8fc,a667ba779a4384caf6343e23c7f2e465c2980869..7743a78d472397bbf9a10c0b1ac2d7e4b163a6a6
  #include <linux/devfreq.h>
  #include <linux/devfreq_cooling.h>
  #include <linux/export.h>
+ #include <linux/idr.h>
  #include <linux/slab.h>
  #include <linux/pm_opp.h>
  #include <linux/thermal.h>
  
  #include <trace/events/thermal.h>
  
- static DEFINE_MUTEX(devfreq_lock);
- static DEFINE_IDR(devfreq_idr);
+ static DEFINE_IDA(devfreq_ida);
  
  /**
   * struct devfreq_cooling_device - Devfreq cooling device
@@@ -57,42 -57,6 +57,6 @@@ struct devfreq_cooling_device 
        struct devfreq_cooling_power *power_ops;
  };
  
- /**
-  * get_idr - function to get a unique id.
-  * @idr: struct idr * handle used to create a id.
-  * @id: int * value generated by this function.
-  *
-  * This function will populate @id with an unique
-  * id, using the idr API.
-  *
-  * Return: 0 on success, an error code on failure.
-  */
- static int get_idr(struct idr *idr, int *id)
- {
-       int ret;
-       mutex_lock(&devfreq_lock);
-       ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL);
-       mutex_unlock(&devfreq_lock);
-       if (unlikely(ret < 0))
-               return ret;
-       *id = ret;
-       return 0;
- }
- /**
-  * release_idr - function to free the unique id.
-  * @idr: struct idr * handle used for creating the id.
-  * @id: int value representing the unique id.
-  */
- static void release_idr(struct idr *idr, int id)
- {
-       mutex_lock(&devfreq_lock);
-       idr_remove(idr, id);
-       mutex_unlock(&devfreq_lock);
- }
  /**
   * partition_enable_opps() - disable all opps above a given state
   * @dfc:      Pointer to devfreq we are operating on
@@@ -113,15 -77,15 +77,15 @@@ static int partition_enable_opps(struc
                unsigned int freq = dfc->freq_table[i];
                bool want_enable = i >= cdev_state ? true : false;
  
 -              rcu_read_lock();
                opp = dev_pm_opp_find_freq_exact(dev, freq, !want_enable);
 -              rcu_read_unlock();
  
                if (PTR_ERR(opp) == -ERANGE)
                        continue;
                else if (IS_ERR(opp))
                        return PTR_ERR(opp);
  
 +              dev_pm_opp_put(opp);
 +
                if (want_enable)
                        ret = dev_pm_opp_enable(dev, freq);
                else
@@@ -221,12 -185,15 +185,12 @@@ get_static_power(struct devfreq_cooling
        if (!dfc->power_ops->get_static_power)
                return 0;
  
 -      rcu_read_lock();
 -
        opp = dev_pm_opp_find_freq_exact(dev, freq, true);
        if (IS_ERR(opp) && (PTR_ERR(opp) == -ERANGE))
                opp = dev_pm_opp_find_freq_exact(dev, freq, false);
  
        voltage = dev_pm_opp_get_voltage(opp) / 1000; /* mV */
 -
 -      rcu_read_unlock();
 +      dev_pm_opp_put(opp);
  
        if (voltage == 0) {
                dev_warn_ratelimited(dev,
@@@ -409,14 -376,18 +373,14 @@@ static int devfreq_cooling_gen_tables(s
                unsigned long power_dyn, voltage;
                struct dev_pm_opp *opp;
  
 -              rcu_read_lock();
 -
                opp = dev_pm_opp_find_freq_floor(dev, &freq);
                if (IS_ERR(opp)) {
 -                      rcu_read_unlock();
                        ret = PTR_ERR(opp);
                        goto free_tables;
                }
  
                voltage = dev_pm_opp_get_voltage(opp) / 1000; /* mV */
 -
 -              rcu_read_unlock();
 +              dev_pm_opp_put(opp);
  
                if (dfc->power_ops) {
                        power_dyn = get_dynamic_power(dfc, freq, voltage);
@@@ -489,9 -460,10 +453,10 @@@ of_devfreq_cooling_register_power(struc
        if (err)
                goto free_dfc;
  
-       err = get_idr(&devfreq_idr, &dfc->id);
-       if (err)
+       err = ida_simple_get(&devfreq_ida, 0, 0, GFP_KERNEL);
+       if (err < 0)
                goto free_tables;
+       dfc->id = err;
  
        snprintf(dev_name, sizeof(dev_name), "thermal-devfreq-%d", dfc->id);
  
                dev_err(df->dev.parent,
                        "Failed to register devfreq cooling device (%d)\n",
                        err);
-               goto release_idr;
+               goto release_ida;
        }
  
        dfc->cdev = cdev;
  
        return cdev;
  
- release_idr:
-       release_idr(&devfreq_idr, dfc->id);
+ release_ida:
+       ida_simple_remove(&devfreq_ida, dfc->id);
  free_tables:
        kfree(dfc->power_table);
        kfree(dfc->freq_table);
@@@ -558,7 -530,7 +523,7 @@@ void devfreq_cooling_unregister(struct 
        dfc = cdev->devdata;
  
        thermal_cooling_device_unregister(dfc->cdev);
-       release_idr(&devfreq_idr, dfc->id);
+       ida_simple_remove(&devfreq_ida, dfc->id);
        kfree(dfc->power_table);
        kfree(dfc->freq_table);