All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] PM / devfreq: Remove list_for_each_entry() in devfreq_add_governor()
@ 2019-07-30  8:10 Yue Hu
  0 siblings, 0 replies; only message in thread
From: Yue Hu @ 2019-07-30  8:10 UTC (permalink / raw
  To: myungjoo.ham, kyungmin.park, cw00.choi; +Cc: linux-pm, huyue2, zhangwen

From: Yue Hu <huyue2@yulong.com>

If one governor is built as module, check calling logic below in
successful path:

  devfreq_add_device()              try_then_request_governor()
    try_then_request_governor()       devfreq_add_governor()
    devfreq->governor = governor;       list_for_each_entry() {
    start governor                        devfreq->governor = governor;
                                          start governor
                                        }

Obviously, we have duplicated governor operations. And the relevant
check like name in list_for_each_entry() is needless also.

For built-in governor, devfreq_add_governor() will be called before
calling devfreq_add_device(). That means ->governor_name would not be
equal to ->name.

Thus, let's drop the list_for_each_entry() in devfreq_add_governor().

Moreover, use -EEXIST instead of -EINVAL in devfreq_add_{governor,device},
update message related also.

Signed-off-by: Yue Hu <huyue2@yulong.com>
---
v2: correct syntax error in description
v3: update the description totally

 drivers/devfreq/devfreq.c | 39 +++------------------------------------
 1 file changed, 3 insertions(+), 36 deletions(-)

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);
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-30  8:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-30  8:10 [PATCH v3] PM / devfreq: Remove list_for_each_entry() in devfreq_add_governor() Yue Hu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.