PM / devfreq: Remove list_for_each_entry() in devfreq_add_governor()
PATCH v2 1/1 PM / devfreq: Remove list_for_each_entry() in devfreq_add_governor()
From: Yue Hu <[email protected]>
We will call try_then_request_governor() to find a governor from a list of devfreq_governor_list in devfreq_add_device(). Only if the governor has been registered in this list, the devfreq adding will be successful, fails if not. That means we should do the governor registration charged by devfreq_add_governor() before adding devfreq for a device with this governor. So, the devfreq_list would not contain the device which has the governor to be added when registering governor.
Moreover, use EEXIST instead of EINVAL in devfreq_add_{governor,device}, update message existing related also.
Signed-off-by Yue Hu <[email protected]>
---
v2: correct syntax error in description
drivers/devfreq/devfreq.c | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-)
drivers/devfreq/devfreq.c +3 -36
@@ -625,9 +625,9 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq =find_device_devfreq (dev);mutex_unlock (&devfreq_list_lock);if (!IS_ERR (devfreq)) { -dev_err (dev,"%s: Unable to create devfreq for the device.\n" , +dev_err (dev,"%s: Existing devfreq for the device.\n" , __func__); - err = -EINVAL ; + err = -EEXIST ; goto err_out; }
@@ -998,7 +998,6 @@ void devfreq_resume(void)int devfreq_add_governor (struct devfreq_governor *governor) {struct devfreq_governor *g; -struct devfreq *devfreq;int err =0 ;if (!governor) {
@@ -1011,44 +1010,12 @@ int devfreq_add_governor(struct devfreq_governor *governor)if (!IS_ERR (g)) {pr_err ("%s: governor %s already registered\n" , __func__, g->name); - err = -EINVAL ; + err = -EEXIST ; goto err_out; }list_add (&governor->node, &devfreq_governor_list); -list_for_each_entry (devfreq, &devfreq_list, node) { -int ret =0 ; -struct device *dev = devfreq->dev.parent; - -if (!strncmp (devfreq->governor_name, governor->name, -DEVFREQ_NAME_LEN )) { -/* The following should never occur */ -if (devfreq->governor) { -dev_warn (dev, -"%s: Governor %s already present\n" , - __func__, devfreq->governor->name); - ret = devfreq->governor->event_handler (devfreq, -DEVFREQ_GOV_STOP ,NULL ); -if (ret) { -dev_warn (dev, -"%s: Governor %s stop = %d\n" , - __func__, - devfreq->governor->name, ret); - } -/* Fall through */ - } - devfreq->governor = governor; - ret = devfreq->governor->event_handler (devfreq, -DEVFREQ_GOV_START ,NULL ); -if (ret) { -dev_warn (dev,"%s: Governor %s start=%d\n" , - __func__, devfreq->governor->name, - ret); - } - } - } - err_out:mutex_unlock (&devfreq_list_lock);
Signature · 1 line
1.9.1