@@ -23,12 +23,12 @@
#include <linux/cpufreq.h>
#include <linux/device.h>
#include <linux/err.h>
-#include <linux/idr.h>
#include <linux/mutex.h>
#include <linux/pm_opp.h>
#include <linux/slab.h>
#include <linux/thermal.h>
#include <linux/clock_cooling.h>
+#include "thermal_core.h"
/**
* struct clock_cooling_device - data for cooling device with clock
@@ -65,43 +65,9 @@ struct clock_cooling_device {
};
#define to_clock_cooling_device(x) \
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 */
enum clock_cooling_property {
@@ -432,7 +398,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
if (IS_ERR(ccdev->clk))
return ERR_CAST(ccdev->clk);
- ret = clock_cooling_get_idr(&ccdev->id);
+ ret = get_ida(&clock_ida, &cooling_clock_lock, &ccdev->id);
if (ret)
return ERR_PTR(-EINVAL);
@@ -441,7 +407,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
cdev = thermal_cooling_device_register(dev_name, ccdev,
&clock_cooling_ops);
if (IS_ERR(cdev)) {
- release_idr(ccdev->id);
+ release_ida(&clock_ida, &cooling_clock_lock, ccdev->id);
return ERR_PTR(-EINVAL);
}
ccdev->cdev = cdev;
@@ -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 */
ret = dev_pm_opp_init_cpufreq_table(dev, &ccdev->freq_table);
if (ret) {
- release_idr(ccdev->id);
+ release_ida(&clock_ida, &cooling_clock_lock, ccdev->id);
return ERR_PTR(ret);
}
ccdev->clock_state = 0;
@@ -481,6 +447,6 @@ void clock_cooling_unregister(struct thermal_cooling_device *cdev)
dev_pm_opp_free_cpufreq_table(ccdev->dev, &ccdev->freq_table);
thermal_cooling_device_unregister(ccdev->cdev);
- release_idr(ccdev->id);
+ release_ida(&clock_ida, &cooling_clock_lock, ccdev->id);
}
EXPORT_SYMBOL_GPL(clock_cooling_unregister);
thermal clock cooling currently uses IDRs to allocate IDs, but it only needs to know whether IDs are in use or not; the ID to pointer functionality of the IDR is unused. That means it can use the more space-efficient IDA. CC: Matthew Wilcox <mawilcox@microsoft.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com> --- drivers/thermal/clock_cooling.c | 46 ++++++----------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-)