From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zhang Rui Subject: [PATCH 5/5] thermal: clock cooling: convert ID allocation to IDA Date: Wed, 21 Dec 2016 10:04:15 +0800 Message-ID: <1482285855-2974-6-git-send-email-rui.zhang@intel.com> References: <1482285855-2974-1-git-send-email-rui.zhang@intel.com> Return-path: Received: from mga02.intel.com ([134.134.136.20]:65334 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932778AbcLUCEZ (ORCPT ); Tue, 20 Dec 2016 21:04:25 -0500 In-Reply-To: <1482285855-2974-1-git-send-email-rui.zhang@intel.com> Sender: linux-pm-owner@vger.kernel.org List-Id: linux-pm@vger.kernel.org To: linux-pm@vger.kernel.org Cc: Matthew Wilcox , Zhang Rui 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 Signed-off-by: Zhang Rui --- drivers/thermal/clock_cooling.c | 46 ++++++----------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/drivers/thermal/clock_cooling.c b/drivers/thermal/clock_cooling.c index ed5dd0e..f84a8d8 100644 --- a/drivers/thermal/clock_cooling.c +++ b/drivers/thermal/clock_cooling.c @@ -23,12 +23,12 @@ #include #include #include -#include #include #include #include #include #include +#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); -- 2.7.4