diff mbox series

PM / devfreq: Remove list_for_each_entry() in devfreq_add_governor()

Message ID 20190729092617.9032-1-zbestahu@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show
Series PM / devfreq: Remove list_for_each_entry() in devfreq_add_governor() | expand

Commit Message

Yue Hu July 29, 2019, 9:26 a.m. UTC
From: Yue Hu <huyue2@yulong.com>

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 contains 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 <huyue2@yulong.com>
---
 drivers/devfreq/devfreq.c | 39 +++------------------------------------
 1 file changed, 3 insertions(+), 36 deletions(-)
diff mbox series

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 784c08e..104f03d 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -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);