[PATCH] spi: Use pm_runtime_resume_and_get() to replace open coding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux