Commit 7a6639dc authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Zhang Rui

thermal: convert clock cooling to use an IDA

thermal clock cooling does not use the ability to look up pointers by ID,
so convert it from using an IDR to the more space-efficient IDA.
Signed-off-by: default avatarMatthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
parent b31ef828
...@@ -65,42 +65,7 @@ struct clock_cooling_device { ...@@ -65,42 +65,7 @@ struct clock_cooling_device {
}; };
#define to_clock_cooling_device(x) \ #define to_clock_cooling_device(x) \
container_of(x, struct clock_cooling_device, clk_rate_change_nb) container_of(x, struct clock_cooling_device, clk_rate_change_nb)
static DEFINE_IDR(clock_idr); static DEFINE_IDA(clock_ida);
static DEFINE_MUTEX(cooling_clock_lock);
/**
* clock_cooling_get_idr - function to get an unique 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 clock_cooling_get_idr(int *id)
{
int ret;
mutex_lock(&cooling_clock_lock);
ret = idr_alloc(&clock_idr, NULL, 0, 0, GFP_KERNEL);
mutex_unlock(&cooling_clock_lock);
if (unlikely(ret < 0))
return ret;
*id = ret;
return 0;
}
/**
* release_idr - function to free the unique id.
* @id: int value representing the unique id.
*/
static void release_idr(int id)
{
mutex_lock(&cooling_clock_lock);
idr_remove(&clock_idr, id);
mutex_unlock(&cooling_clock_lock);
}
/* Below code defines functions to be used for clock as cooling device */ /* Below code defines functions to be used for clock as cooling device */
...@@ -432,16 +397,17 @@ clock_cooling_register(struct device *dev, const char *clock_name) ...@@ -432,16 +397,17 @@ clock_cooling_register(struct device *dev, const char *clock_name)
if (IS_ERR(ccdev->clk)) if (IS_ERR(ccdev->clk))
return ERR_CAST(ccdev->clk); return ERR_CAST(ccdev->clk);
ret = clock_cooling_get_idr(&ccdev->id); ret = ida_simple_get(&clock_ida, 0, 0, GFP_KERNEL);
if (ret) if (ret < 0)
return ERR_PTR(-EINVAL); return ERR_PTR(ret);
ccdev->id = ret;
snprintf(dev_name, sizeof(dev_name), "thermal-clock-%d", ccdev->id); snprintf(dev_name, sizeof(dev_name), "thermal-clock-%d", ccdev->id);
cdev = thermal_cooling_device_register(dev_name, ccdev, cdev = thermal_cooling_device_register(dev_name, ccdev,
&clock_cooling_ops); &clock_cooling_ops);
if (IS_ERR(cdev)) { if (IS_ERR(cdev)) {
release_idr(ccdev->id); ida_simple_remove(&clock_ida, ccdev->id);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
ccdev->cdev = cdev; ccdev->cdev = cdev;
...@@ -450,7 +416,7 @@ clock_cooling_register(struct device *dev, const char *clock_name) ...@@ -450,7 +416,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
/* Assuming someone has already filled the opp table for this device */ /* Assuming someone has already filled the opp table for this device */
ret = dev_pm_opp_init_cpufreq_table(dev, &ccdev->freq_table); ret = dev_pm_opp_init_cpufreq_table(dev, &ccdev->freq_table);
if (ret) { if (ret) {
release_idr(ccdev->id); ida_simple_remove(&clock_ida, ccdev->id);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
ccdev->clock_state = 0; ccdev->clock_state = 0;
...@@ -481,6 +447,6 @@ void clock_cooling_unregister(struct thermal_cooling_device *cdev) ...@@ -481,6 +447,6 @@ void clock_cooling_unregister(struct thermal_cooling_device *cdev)
dev_pm_opp_free_cpufreq_table(ccdev->dev, &ccdev->freq_table); dev_pm_opp_free_cpufreq_table(ccdev->dev, &ccdev->freq_table);
thermal_cooling_device_unregister(ccdev->cdev); thermal_cooling_device_unregister(ccdev->cdev);
release_idr(ccdev->id); ida_simple_remove(&clock_ida, ccdev->id);
} }
EXPORT_SYMBOL_GPL(clock_cooling_unregister); EXPORT_SYMBOL_GPL(clock_cooling_unregister);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment