Re: [PATCH V3 3/5] Thermal: Remove the cooling_cpufreq_list.

2012-11-09 Thread Hongbo Zhang
On 7 November 2012 14:54, Zhang Rui  wrote:
> On Tue, 2012-10-30 at 17:48 +0100, hongbo.zhang wrote:
>> From: "hongbo.zhang" 
>>
>> Problem of using this list is that the cpufreq_get_max_state callback will be
>> called when register cooling device by thermal_cooling_device_register, but
>> this list isn't ready at this moment. What's more, there is no need to 
>> maintain
>> such a list, we can get cpufreq_cooling_device instance by the private
>> thermal_cooling_device.devdata.
>>
>> Signed-off-by: hongbo.zhang 
>> Reviewed-by: Francesco Lavra 
>> Reviewed-by: Amit Daniel Kachhap 
>
> applied to thermal-next.
Thanks.
I have sent the other updated 4/5 5/5 patches with Reviewed-by added
in a new thread, please have a look there.

>
> thanks,
> rui
>
>> ---
>>  drivers/thermal/cpu_cooling.c | 91 
>> +--
>>  1 file changed, 19 insertions(+), 72 deletions(-)
>>
>> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
>> index bfd62b7..392d57d 100644
>> --- a/drivers/thermal/cpu_cooling.c
>> +++ b/drivers/thermal/cpu_cooling.c
>> @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
>>  };
>>  static LIST_HEAD(cooling_cpufreq_list);
>>  static DEFINE_IDR(cpufreq_idr);
>> +static DEFINE_MUTEX(cooling_cpufreq_lock);
>>
>> -static struct mutex cooling_cpufreq_lock;
>> +static unsigned int cpufreq_dev_count;
>>
>>  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
>>  #define NOTIFY_INVALID NULL
>> @@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct 
>> notifier_block *nb,
>>  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
>>unsigned long *state)
>>  {
>> - int ret = -EINVAL, i = 0;
>> - struct cpufreq_cooling_device *cpufreq_device;
>> - struct cpumask *maskPtr;
>> + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>> + struct cpumask *maskPtr = _device->allowed_cpus;
>>   unsigned int cpu;
>>   struct cpufreq_frequency_table *table;
>>   unsigned long count = 0;
>> + int i = 0;
>>
>> - mutex_lock(_cpufreq_lock);
>> - list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
>> - if (cpufreq_device && cpufreq_device->cool_dev == cdev)
>> - break;
>> - }
>> - if (cpufreq_device == NULL)
>> - goto return_get_max_state;
>> -
>> - maskPtr = _device->allowed_cpus;
>>   cpu = cpumask_any(maskPtr);
>>   table = cpufreq_frequency_get_table(cpu);
>>   if (!table) {
>>   *state = 0;
>> - ret = 0;
>> - goto return_get_max_state;
>> + return 0;
>>   }
>>
>>   for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
>> @@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
>> thermal_cooling_device *cdev,
>>
>>   if (count > 0) {
>>   *state = --count;
>> - ret = 0;
>> + return 0;
>>   }
>>
>> -return_get_max_state:
>> - mutex_unlock(_cpufreq_lock);
>> - return ret;
>> + return -EINVAL;
>>  }
>>
>>  /**
>> @@ -288,20 +277,10 @@ return_get_max_state:
>>  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
>>unsigned long *state)
>>  {
>> - int ret = -EINVAL;
>> - struct cpufreq_cooling_device *cpufreq_device;
>> + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>>
>> - mutex_lock(_cpufreq_lock);
>> - list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
>> - if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
>> - *state = cpufreq_device->cpufreq_state;
>> - ret = 0;
>> - break;
>> - }
>> - }
>> - mutex_unlock(_cpufreq_lock);
>> -
>> - return ret;
>> + *state = cpufreq_device->cpufreq_state;
>> + return 0;
>>  }
>>
>>  /**
>> @@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
>> thermal_cooling_device *cdev,
>>  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
>>unsigned long state)
>>  {
>> - int ret = -EINVAL;
>> - struct cpufreq_cooling_device *cpufreq_device;
>> + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>>
>> - mutex_lock(_cpufreq_lock);
>> - list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
>> - if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
>> - ret = 0;
>> - break;
>> - }
>> - }
>> - if (!ret)
>> - ret = cpufreq_apply_cooling(cpufreq_device, state);
>> -
>> - mutex_unlock(_cpufreq_lock);
>> -
>> - return ret;
>> + return cpufreq_apply_cooling(cpufreq_device, state);
>>  }
>>
>>  /* Bind cpufreq callbacks to thermal cooling device ops */
>> @@ -351,14 +317,11 @@ struct thermal_cooling_device 
>> 

Re: [PATCH V3 3/5] Thermal: Remove the cooling_cpufreq_list.

2012-11-09 Thread Hongbo Zhang
On 7 November 2012 14:54, Zhang Rui rui.zh...@intel.com wrote:
 On Tue, 2012-10-30 at 17:48 +0100, hongbo.zhang wrote:
 From: hongbo.zhang hongbo.zh...@linaro.com

 Problem of using this list is that the cpufreq_get_max_state callback will be
 called when register cooling device by thermal_cooling_device_register, but
 this list isn't ready at this moment. What's more, there is no need to 
 maintain
 such a list, we can get cpufreq_cooling_device instance by the private
 thermal_cooling_device.devdata.

 Signed-off-by: hongbo.zhang hongbo.zh...@linaro.com
 Reviewed-by: Francesco Lavra francescolavra...@gmail.com
 Reviewed-by: Amit Daniel Kachhap amit.kach...@linaro.org

 applied to thermal-next.
Thanks.
I have sent the other updated 4/5 5/5 patches with Reviewed-by added
in a new thread, please have a look there.


 thanks,
 rui

 ---
  drivers/thermal/cpu_cooling.c | 91 
 +--
  1 file changed, 19 insertions(+), 72 deletions(-)

 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
 index bfd62b7..392d57d 100644
 --- a/drivers/thermal/cpu_cooling.c
 +++ b/drivers/thermal/cpu_cooling.c
 @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
  };
  static LIST_HEAD(cooling_cpufreq_list);
  static DEFINE_IDR(cpufreq_idr);
 +static DEFINE_MUTEX(cooling_cpufreq_lock);

 -static struct mutex cooling_cpufreq_lock;
 +static unsigned int cpufreq_dev_count;

  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
  #define NOTIFY_INVALID NULL
 @@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct 
 notifier_block *nb,
  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
  {
 - int ret = -EINVAL, i = 0;
 - struct cpufreq_cooling_device *cpufreq_device;
 - struct cpumask *maskPtr;
 + struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 + struct cpumask *maskPtr = cpufreq_device-allowed_cpus;
   unsigned int cpu;
   struct cpufreq_frequency_table *table;
   unsigned long count = 0;
 + int i = 0;

 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 - if (cpufreq_device  cpufreq_device-cool_dev == cdev)
 - break;
 - }
 - if (cpufreq_device == NULL)
 - goto return_get_max_state;
 -
 - maskPtr = cpufreq_device-allowed_cpus;
   cpu = cpumask_any(maskPtr);
   table = cpufreq_frequency_get_table(cpu);
   if (!table) {
   *state = 0;
 - ret = 0;
 - goto return_get_max_state;
 + return 0;
   }

   for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
 @@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,

   if (count  0) {
   *state = --count;
 - ret = 0;
 + return 0;
   }

 -return_get_max_state:
 - mutex_unlock(cooling_cpufreq_lock);
 - return ret;
 + return -EINVAL;
  }

  /**
 @@ -288,20 +277,10 @@ return_get_max_state:
  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
  {
 - int ret = -EINVAL;
 - struct cpufreq_cooling_device *cpufreq_device;
 + struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;

 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 - if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
 - *state = cpufreq_device-cpufreq_state;
 - ret = 0;
 - break;
 - }
 - }
 - mutex_unlock(cooling_cpufreq_lock);
 -
 - return ret;
 + *state = cpufreq_device-cpufreq_state;
 + return 0;
  }

  /**
 @@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
 thermal_cooling_device *cdev,
  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
  {
 - int ret = -EINVAL;
 - struct cpufreq_cooling_device *cpufreq_device;
 + struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;

 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 - if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
 - ret = 0;
 - break;
 - }
 - }
 - if (!ret)
 - ret = cpufreq_apply_cooling(cpufreq_device, state);
 -
 - mutex_unlock(cooling_cpufreq_lock);
 -
 - return ret;
 + return cpufreq_apply_cooling(cpufreq_device, state);
  }

  /* Bind cpufreq callbacks to thermal cooling device ops */
 @@ -351,14 +317,11 @@ struct thermal_cooling_device 
 *cpufreq_cooling_register(
  {
   struct thermal_cooling_device *cool_dev;
   struct cpufreq_cooling_device 

Re: [PATCH V3 3/5] Thermal: Remove the cooling_cpufreq_list.

2012-11-06 Thread Zhang Rui
On Tue, 2012-10-30 at 17:48 +0100, hongbo.zhang wrote:
> From: "hongbo.zhang" 
> 
> Problem of using this list is that the cpufreq_get_max_state callback will be
> called when register cooling device by thermal_cooling_device_register, but
> this list isn't ready at this moment. What's more, there is no need to 
> maintain
> such a list, we can get cpufreq_cooling_device instance by the private
> thermal_cooling_device.devdata.
> 
> Signed-off-by: hongbo.zhang 
> Reviewed-by: Francesco Lavra 
> Reviewed-by: Amit Daniel Kachhap 

applied to thermal-next.

thanks,
rui

> ---
>  drivers/thermal/cpu_cooling.c | 91 
> +--
>  1 file changed, 19 insertions(+), 72 deletions(-)
> 
> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
> index bfd62b7..392d57d 100644
> --- a/drivers/thermal/cpu_cooling.c
> +++ b/drivers/thermal/cpu_cooling.c
> @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
>  };
>  static LIST_HEAD(cooling_cpufreq_list);
>  static DEFINE_IDR(cpufreq_idr);
> +static DEFINE_MUTEX(cooling_cpufreq_lock);
>  
> -static struct mutex cooling_cpufreq_lock;
> +static unsigned int cpufreq_dev_count;
>  
>  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
>  #define NOTIFY_INVALID NULL
> @@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct 
> notifier_block *nb,
>  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
>unsigned long *state)
>  {
> - int ret = -EINVAL, i = 0;
> - struct cpufreq_cooling_device *cpufreq_device;
> - struct cpumask *maskPtr;
> + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
> + struct cpumask *maskPtr = _device->allowed_cpus;
>   unsigned int cpu;
>   struct cpufreq_frequency_table *table;
>   unsigned long count = 0;
> + int i = 0;
>  
> - mutex_lock(_cpufreq_lock);
> - list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
> - if (cpufreq_device && cpufreq_device->cool_dev == cdev)
> - break;
> - }
> - if (cpufreq_device == NULL)
> - goto return_get_max_state;
> -
> - maskPtr = _device->allowed_cpus;
>   cpu = cpumask_any(maskPtr);
>   table = cpufreq_frequency_get_table(cpu);
>   if (!table) {
>   *state = 0;
> - ret = 0;
> - goto return_get_max_state;
> + return 0;
>   }
>  
>   for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
> @@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
> thermal_cooling_device *cdev,
>  
>   if (count > 0) {
>   *state = --count;
> - ret = 0;
> + return 0;
>   }
>  
> -return_get_max_state:
> - mutex_unlock(_cpufreq_lock);
> - return ret;
> + return -EINVAL;
>  }
>  
>  /**
> @@ -288,20 +277,10 @@ return_get_max_state:
>  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
>unsigned long *state)
>  {
> - int ret = -EINVAL;
> - struct cpufreq_cooling_device *cpufreq_device;
> + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>  
> - mutex_lock(_cpufreq_lock);
> - list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
> - if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
> - *state = cpufreq_device->cpufreq_state;
> - ret = 0;
> - break;
> - }
> - }
> - mutex_unlock(_cpufreq_lock);
> -
> - return ret;
> + *state = cpufreq_device->cpufreq_state;
> + return 0;
>  }
>  
>  /**
> @@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
> thermal_cooling_device *cdev,
>  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
>unsigned long state)
>  {
> - int ret = -EINVAL;
> - struct cpufreq_cooling_device *cpufreq_device;
> + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>  
> - mutex_lock(_cpufreq_lock);
> - list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
> - if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
> - ret = 0;
> - break;
> - }
> - }
> - if (!ret)
> - ret = cpufreq_apply_cooling(cpufreq_device, state);
> -
> - mutex_unlock(_cpufreq_lock);
> -
> - return ret;
> + return cpufreq_apply_cooling(cpufreq_device, state);
>  }
>  
>  /* Bind cpufreq callbacks to thermal cooling device ops */
> @@ -351,14 +317,11 @@ struct thermal_cooling_device *cpufreq_cooling_register(
>  {
>   struct thermal_cooling_device *cool_dev;
>   struct cpufreq_cooling_device *cpufreq_dev = NULL;
> - unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
> + unsigned int min = 0, max = 0;
>   char dev_name[THERMAL_NAME_LENGTH];
>   int ret = 0, 

Re: [PATCH V3 3/5] Thermal: Remove the cooling_cpufreq_list.

2012-11-06 Thread Zhang Rui
On Tue, 2012-10-30 at 17:48 +0100, hongbo.zhang wrote:
 From: hongbo.zhang hongbo.zh...@linaro.com
 
 Problem of using this list is that the cpufreq_get_max_state callback will be
 called when register cooling device by thermal_cooling_device_register, but
 this list isn't ready at this moment. What's more, there is no need to 
 maintain
 such a list, we can get cpufreq_cooling_device instance by the private
 thermal_cooling_device.devdata.
 
 Signed-off-by: hongbo.zhang hongbo.zh...@linaro.com
 Reviewed-by: Francesco Lavra francescolavra...@gmail.com
 Reviewed-by: Amit Daniel Kachhap amit.kach...@linaro.org

applied to thermal-next.

thanks,
rui

 ---
  drivers/thermal/cpu_cooling.c | 91 
 +--
  1 file changed, 19 insertions(+), 72 deletions(-)
 
 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
 index bfd62b7..392d57d 100644
 --- a/drivers/thermal/cpu_cooling.c
 +++ b/drivers/thermal/cpu_cooling.c
 @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
  };
  static LIST_HEAD(cooling_cpufreq_list);
  static DEFINE_IDR(cpufreq_idr);
 +static DEFINE_MUTEX(cooling_cpufreq_lock);
  
 -static struct mutex cooling_cpufreq_lock;
 +static unsigned int cpufreq_dev_count;
  
  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
  #define NOTIFY_INVALID NULL
 @@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct 
 notifier_block *nb,
  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
  {
 - int ret = -EINVAL, i = 0;
 - struct cpufreq_cooling_device *cpufreq_device;
 - struct cpumask *maskPtr;
 + struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 + struct cpumask *maskPtr = cpufreq_device-allowed_cpus;
   unsigned int cpu;
   struct cpufreq_frequency_table *table;
   unsigned long count = 0;
 + int i = 0;
  
 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 - if (cpufreq_device  cpufreq_device-cool_dev == cdev)
 - break;
 - }
 - if (cpufreq_device == NULL)
 - goto return_get_max_state;
 -
 - maskPtr = cpufreq_device-allowed_cpus;
   cpu = cpumask_any(maskPtr);
   table = cpufreq_frequency_get_table(cpu);
   if (!table) {
   *state = 0;
 - ret = 0;
 - goto return_get_max_state;
 + return 0;
   }
  
   for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
 @@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,
  
   if (count  0) {
   *state = --count;
 - ret = 0;
 + return 0;
   }
  
 -return_get_max_state:
 - mutex_unlock(cooling_cpufreq_lock);
 - return ret;
 + return -EINVAL;
  }
  
  /**
 @@ -288,20 +277,10 @@ return_get_max_state:
  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
  {
 - int ret = -EINVAL;
 - struct cpufreq_cooling_device *cpufreq_device;
 + struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
  
 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 - if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
 - *state = cpufreq_device-cpufreq_state;
 - ret = 0;
 - break;
 - }
 - }
 - mutex_unlock(cooling_cpufreq_lock);
 -
 - return ret;
 + *state = cpufreq_device-cpufreq_state;
 + return 0;
  }
  
  /**
 @@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
 thermal_cooling_device *cdev,
  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
  {
 - int ret = -EINVAL;
 - struct cpufreq_cooling_device *cpufreq_device;
 + struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
  
 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 - if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
 - ret = 0;
 - break;
 - }
 - }
 - if (!ret)
 - ret = cpufreq_apply_cooling(cpufreq_device, state);
 -
 - mutex_unlock(cooling_cpufreq_lock);
 -
 - return ret;
 + return cpufreq_apply_cooling(cpufreq_device, state);
  }
  
  /* Bind cpufreq callbacks to thermal cooling device ops */
 @@ -351,14 +317,11 @@ struct thermal_cooling_device *cpufreq_cooling_register(
  {
   struct thermal_cooling_device *cool_dev;
   struct cpufreq_cooling_device *cpufreq_dev = NULL;
 - unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
 + unsigned int min = 0, max = 0;
   char dev_name[THERMAL_NAME_LENGTH];
  

[PATCH V3 3/5] Thermal: Remove the cooling_cpufreq_list.

2012-10-30 Thread hongbo.zhang
From: "hongbo.zhang" 

Problem of using this list is that the cpufreq_get_max_state callback will be
called when register cooling device by thermal_cooling_device_register, but
this list isn't ready at this moment. What's more, there is no need to maintain
such a list, we can get cpufreq_cooling_device instance by the private
thermal_cooling_device.devdata.

Signed-off-by: hongbo.zhang 
Reviewed-by: Francesco Lavra 
Reviewed-by: Amit Daniel Kachhap 
---
 drivers/thermal/cpu_cooling.c | 91 +--
 1 file changed, 19 insertions(+), 72 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index bfd62b7..392d57d 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
 };
 static LIST_HEAD(cooling_cpufreq_list);
 static DEFINE_IDR(cpufreq_idr);
+static DEFINE_MUTEX(cooling_cpufreq_lock);
 
-static struct mutex cooling_cpufreq_lock;
+static unsigned int cpufreq_dev_count;
 
 /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
 #define NOTIFY_INVALID NULL
@@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct notifier_block 
*nb,
 static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL, i = 0;
-   struct cpufreq_cooling_device *cpufreq_device;
-   struct cpumask *maskPtr;
+   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
+   struct cpumask *maskPtr = _device->allowed_cpus;
unsigned int cpu;
struct cpufreq_frequency_table *table;
unsigned long count = 0;
+   int i = 0;
 
-   mutex_lock(_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
-   if (cpufreq_device && cpufreq_device->cool_dev == cdev)
-   break;
-   }
-   if (cpufreq_device == NULL)
-   goto return_get_max_state;
-
-   maskPtr = _device->allowed_cpus;
cpu = cpumask_any(maskPtr);
table = cpufreq_frequency_get_table(cpu);
if (!table) {
*state = 0;
-   ret = 0;
-   goto return_get_max_state;
+   return 0;
}
 
for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
@@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
 
if (count > 0) {
*state = --count;
-   ret = 0;
+   return 0;
}
 
-return_get_max_state:
-   mutex_unlock(_cpufreq_lock);
-   return ret;
+   return -EINVAL;
 }
 
 /**
@@ -288,20 +277,10 @@ return_get_max_state:
 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
 
-   mutex_lock(_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
-   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
-   *state = cpufreq_device->cpufreq_state;
-   ret = 0;
-   break;
-   }
-   }
-   mutex_unlock(_cpufreq_lock);
-
-   return ret;
+   *state = cpufreq_device->cpufreq_state;
+   return 0;
 }
 
 /**
@@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 unsigned long state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
 
-   mutex_lock(_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
-   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
-   ret = 0;
-   break;
-   }
-   }
-   if (!ret)
-   ret = cpufreq_apply_cooling(cpufreq_device, state);
-
-   mutex_unlock(_cpufreq_lock);
-
-   return ret;
+   return cpufreq_apply_cooling(cpufreq_device, state);
 }
 
 /* Bind cpufreq callbacks to thermal cooling device ops */
@@ -351,14 +317,11 @@ struct thermal_cooling_device *cpufreq_cooling_register(
 {
struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL;
-   unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
+   unsigned int min = 0, max = 0;
char dev_name[THERMAL_NAME_LENGTH];
int ret = 0, i;
struct cpufreq_policy policy;
 
-   list_for_each_entry(cpufreq_dev, _cpufreq_list, node)
-   cpufreq_dev_count++;
-
/*Verify that all the clip cpus have same freq_min, freq_max limit*/

[PATCH V3 3/5] Thermal: Remove the cooling_cpufreq_list.

2012-10-30 Thread hongbo.zhang
From: hongbo.zhang hongbo.zh...@linaro.com

Problem of using this list is that the cpufreq_get_max_state callback will be
called when register cooling device by thermal_cooling_device_register, but
this list isn't ready at this moment. What's more, there is no need to maintain
such a list, we can get cpufreq_cooling_device instance by the private
thermal_cooling_device.devdata.

Signed-off-by: hongbo.zhang hongbo.zh...@linaro.com
Reviewed-by: Francesco Lavra francescolavra...@gmail.com
Reviewed-by: Amit Daniel Kachhap amit.kach...@linaro.org
---
 drivers/thermal/cpu_cooling.c | 91 +--
 1 file changed, 19 insertions(+), 72 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index bfd62b7..392d57d 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
 };
 static LIST_HEAD(cooling_cpufreq_list);
 static DEFINE_IDR(cpufreq_idr);
+static DEFINE_MUTEX(cooling_cpufreq_lock);
 
-static struct mutex cooling_cpufreq_lock;
+static unsigned int cpufreq_dev_count;
 
 /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
 #define NOTIFY_INVALID NULL
@@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct notifier_block 
*nb,
 static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL, i = 0;
-   struct cpufreq_cooling_device *cpufreq_device;
-   struct cpumask *maskPtr;
+   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
+   struct cpumask *maskPtr = cpufreq_device-allowed_cpus;
unsigned int cpu;
struct cpufreq_frequency_table *table;
unsigned long count = 0;
+   int i = 0;
 
-   mutex_lock(cooling_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
-   if (cpufreq_device  cpufreq_device-cool_dev == cdev)
-   break;
-   }
-   if (cpufreq_device == NULL)
-   goto return_get_max_state;
-
-   maskPtr = cpufreq_device-allowed_cpus;
cpu = cpumask_any(maskPtr);
table = cpufreq_frequency_get_table(cpu);
if (!table) {
*state = 0;
-   ret = 0;
-   goto return_get_max_state;
+   return 0;
}
 
for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
@@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
 
if (count  0) {
*state = --count;
-   ret = 0;
+   return 0;
}
 
-return_get_max_state:
-   mutex_unlock(cooling_cpufreq_lock);
-   return ret;
+   return -EINVAL;
 }
 
 /**
@@ -288,20 +277,10 @@ return_get_max_state:
 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 
-   mutex_lock(cooling_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
-   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
-   *state = cpufreq_device-cpufreq_state;
-   ret = 0;
-   break;
-   }
-   }
-   mutex_unlock(cooling_cpufreq_lock);
-
-   return ret;
+   *state = cpufreq_device-cpufreq_state;
+   return 0;
 }
 
 /**
@@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 unsigned long state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 
-   mutex_lock(cooling_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
-   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
-   ret = 0;
-   break;
-   }
-   }
-   if (!ret)
-   ret = cpufreq_apply_cooling(cpufreq_device, state);
-
-   mutex_unlock(cooling_cpufreq_lock);
-
-   return ret;
+   return cpufreq_apply_cooling(cpufreq_device, state);
 }
 
 /* Bind cpufreq callbacks to thermal cooling device ops */
@@ -351,14 +317,11 @@ struct thermal_cooling_device *cpufreq_cooling_register(
 {
struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL;
-   unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
+   unsigned int min = 0, max = 0;
char dev_name[THERMAL_NAME_LENGTH];
int ret = 0, i;
struct cpufreq_policy policy;
 
-