mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthias Kaehlcke <mka@chromium.org>
To: MyungJoo Ham <myungjoo.ham@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-tegra@vger.kernel.org,
	Lukasz Luba <l.luba@partner.samsung.com>
Cc: Matthias Kaehlcke <mka@chromium.org>
Subject: [PATCH 3/4] PM / devfreq: Add devfreq_governor_start/stop()
Date: Wed, 13 Feb 2019 17:30:41 -0800	[thread overview]
Message-ID: <20190214013042.254790-4-mka@chromium.org> (raw)
In-Reply-To: <20190214013042.254790-1-mka@chromium.org>

The following pattern is repeated multiple times:

- call governor event handler with DEVFREQ_GOV_START/STOP
- check return value
- in case of error log a message

Add devfreq_governor_start/stop() helper functions with this code
and call them instead.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 drivers/devfreq/devfreq.c | 96 +++++++++++++++++++++++----------------
 1 file changed, 58 insertions(+), 38 deletions(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 7fab6c4cf719b..eb86461648d74 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -580,6 +580,53 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type,
 	return ret;
 }
 
+/**
+ * devfreq_governor_start() - Start the devfreq governor of the device.
+ * @devfreq:	the devfreq instance
+ */
+static int devfreq_governor_start(struct devfreq *devfreq)
+{
+	struct device *dev = devfreq->dev.parent;
+	int err;
+
+	if (WARN(mutex_is_locked(&devfreq->lock),
+		 "mutex must *not* be held by the caller\n"))
+		return -EINVAL;
+
+	err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_START,
+					       NULL);
+	if (err) {
+		dev_err(dev, "Governor %s not started: %d\n",
+			devfreq->governor->name, err);
+		return err;
+	}
+
+	return 0;
+}
+
+/**
+ * devfreq_governor_stop() - Stop the devfreq governor of the device.
+ * @devfreq:	the devfreq instance
+ */
+static int devfreq_governor_stop(struct devfreq *devfreq)
+{
+	struct device *dev = devfreq->dev.parent;
+	int err;
+
+	if (WARN(mutex_is_locked(&devfreq->lock),
+		 "mutex must *not* be held by the caller\n"))
+		return -EINVAL;
+
+	err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_STOP, NULL);
+	if (err) {
+		dev_warn(dev, "%s: Governor %s not stopped: %d\n",
+			 devfreq->governor->name, err);
+		return err;
+	}
+
+	return 0;
+}
+
 /**
  * devfreq_dev_release() - Callback for struct device to release the device.
  * @dev:	the devfreq device
@@ -720,13 +767,9 @@ struct devfreq *devfreq_add_device(struct device *dev,
 	}
 
 	devfreq->governor = governor;
-	err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_START,
-						NULL);
-	if (err) {
-		dev_err(dev, "%s: Unable to start governor for the device\n",
-			__func__);
+	err = devfreq_governor_start(devfreq);
+	if (err)
 		goto err_init;
-	}
 
 	list_add(&devfreq->node, &devfreq_list);
 
@@ -1029,24 +1072,13 @@ int devfreq_add_governor(struct devfreq_governor *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);
-				}
+				ret = devfreq_governor_stop(devfreq);
+
 				/* 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);
-			}
+			devfreq_governor_start(devfreq);
 		}
 	}
 
@@ -1081,7 +1113,6 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
 		goto err_out;
 	}
 	list_for_each_entry(devfreq, &devfreq_list, node) {
-		int ret;
 		struct device *dev = devfreq->dev.parent;
 
 		if (!strncmp(devfreq->governor_name, governor->name,
@@ -1093,13 +1124,8 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
 				continue;
 				/* Fall through */
 			}
-			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);
-			}
+
+			devfreq_governor_stop(devfreq);
 			devfreq->governor = NULL;
 		}
 	}
@@ -1149,19 +1175,13 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
 	}
 
 	if (df->governor) {
-		ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
-		if (ret) {
-			dev_warn(dev, "%s: Governor %s not stopped(%d)\n",
-				 __func__, df->governor->name, ret);
+		ret = devfreq_governor_stop(df);
+		if (ret)
 			goto out;
-		}
 	}
 	df->governor = governor;
 	strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN);
-	ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
-	if (ret)
-		dev_warn(dev, "%s: Governor %s not started(%d)\n",
-			 __func__, df->governor->name, ret);
+	ret = devfreq_governor_start(df);
 out:
 	mutex_unlock(&devfreq_list_lock);
 
-- 
2.20.1.791.gb4d0f1c61a-goog


  parent reply	other threads:[~2019-02-14  1:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-14  1:30 [PATCH 0/4] PM / devfreq: Refactor load monitoring Matthias Kaehlcke
2019-02-14  1:30 ` [PATCH 1/4] PM / devfreq: Track overall load monitor state instead of 'stop_polling' Matthias Kaehlcke
2019-02-14 14:25   ` Chanwoo Choi
2019-02-14 16:59     ` Matthias Kaehlcke
2019-02-14 23:47       ` Chanwoo Choi
2019-02-14  1:30 ` [PATCH 2/4] PM / devfreq: Handle monitor suspend/resume in the devfreq core Matthias Kaehlcke
2019-02-14 14:10   ` Chanwoo Choi
2019-02-14 17:47     ` Matthias Kaehlcke
2019-02-14  1:30 ` Matthias Kaehlcke [this message]
2019-02-14 14:12   ` [PATCH 3/4] PM / devfreq: Add devfreq_governor_start/stop() Chanwoo Choi
2019-02-14 14:32     ` Chanwoo Choi
2019-02-14 18:32       ` Matthias Kaehlcke
2019-02-14 18:30     ` Matthias Kaehlcke
2019-02-14  1:30 ` [PATCH 4/4] PM / devfreq: Handle monitor start/stop in the devfreq core Matthias Kaehlcke
2019-02-14 14:17   ` Chanwoo Choi
2019-02-14 19:28     ` Matthias Kaehlcke
2019-02-14 23:42       ` Chanwoo Choi
2019-02-15  0:19         ` Matthias Kaehlcke
2019-02-15  0:33           ` Chanwoo Choi
2019-02-15 22:56             ` Matthias Kaehlcke
2019-02-18 11:22               ` Chanwoo Choi
2019-02-14 18:01   ` Lukasz Luba
2019-02-14 19:07     ` Matthias Kaehlcke
2019-02-15 13:07       ` Lukasz Luba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190214013042.254790-4-mka@chromium.org \
    --to=mka@chromium.org \
    --cc=cw00.choi@samsung.com \
    --cc=jonathanh@nvidia.com \
    --cc=kyungmin.park@samsung.com \
    --cc=l.luba@partner.samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®