linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: Use pm_runtime_resume_and_get() to replace open coding
@ 2021-05-20 13:22 Tian Tao
  0 siblings, 0 replies; only message in thread
From: Tian Tao @ 2021-05-20 13:22 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, Tian Tao

use pm_runtime_resume_and_get() to replace pm_runtime_get_sync and
pm_runtime_put_noidle. boilerplate reduction and easier to understand
flow as the new function has no side effects if it returns an error. it
also avoids the problem of positive return values so we can change
if (status < 0) to if (status).

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 drivers/spi/spi.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 57120de..7d25010 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1486,9 +1486,8 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)
 	mutex_lock(&ctlr->io_mutex);
 
 	if (!was_busy && ctlr->auto_runtime_pm) {
-		ret = pm_runtime_get_sync(ctlr->dev.parent);
-		if (ret < 0) {
-			pm_runtime_put_noidle(ctlr->dev.parent);
+		ret = pm_runtime_resume_and_get(ctlr->dev.parent);
+		if (ret) {
 			dev_err(&ctlr->dev, "Failed to power device: %d\n",
 				ret);
 			mutex_unlock(&ctlr->io_mutex);
@@ -3426,10 +3425,9 @@ int spi_setup(struct spi_device *spi)
 	}
 
 	if (spi->controller->auto_runtime_pm && spi->controller->set_cs) {
-		status = pm_runtime_get_sync(spi->controller->dev.parent);
-		if (status < 0) {
+		status = pm_runtime_resume_and_get(spi->controller->dev.parent);
+		if (status) {
 			mutex_unlock(&spi->controller->io_mutex);
-			pm_runtime_put_noidle(spi->controller->dev.parent);
 			dev_err(&spi->controller->dev, "Failed to power device: %d\n",
 				status);
 			return status;
@@ -3491,10 +3489,9 @@ int spi_set_cs_timing(struct spi_device *spi, struct spi_delay *setup,
 		mutex_lock(&spi->controller->io_mutex);
 
 		if (spi->controller->auto_runtime_pm) {
-			status = pm_runtime_get_sync(parent);
-			if (status < 0) {
+			status = pm_runtime_resume_and_get(parent);
+			if (status) {
 				mutex_unlock(&spi->controller->io_mutex);
-				pm_runtime_put_noidle(parent);
 				dev_err(&spi->controller->dev, "Failed to power device: %d\n",
 					status);
 				return status;
-- 
2.7.4


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

only message in thread, other threads:[~2021-05-20 13:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 13:22 [PATCH] spi: Use pm_runtime_resume_and_get() to replace open coding Tian Tao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).