lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon,  2 Nov 2020 19:22:39 +0800
From:   Chunyan Zhang <zhang.lyra@...il.com>
To:     Mark Brown <broonie@...nel.org>
Cc:     linux-spi@...r.kernel.org, linux-kernel@...r.kernel.org,
        Orson Zhai <orsonzhai@...il.com>,
        Baolin Wang <baolin.wang7@...il.com>,
        Chunyan Zhang <zhang.lyra@...il.com>,
        Chunyan Zhang <chunyan.zhang@...soc.com>,
        Bangzheng Liu <bangzheng.liu@...soc.com>
Subject: [PATCH] spi: add runtime PM for transfer_one_message

From: Chunyan Zhang <chunyan.zhang@...soc.com>

Before transfer message, spi devices probably have been in runtime suspended,
that would cause the kernel crash on some platforms once access spi
registers, such as on Unisoc's SoCs. The spi devices can be suspended
until message transfer completed.

Also this patch move the API spi_idle_runtime_pm() above to
spi_transfer_one_message() which need to call that API.

Fixes: b158935f70b9 ("spi: Provide common spi_message processing loop")
Reported-by: Bangzheng Liu <bangzheng.liu@...soc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@...soc.com>
---
 drivers/spi/spi.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 0cab239d8e7f..63f7ebea7076 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1224,6 +1224,14 @@ static void _spi_transfer_cs_change_delay(struct spi_message *msg,
 	}
 }
 
+static void spi_idle_runtime_pm(struct spi_controller *ctlr)
+{
+	if (ctlr->auto_runtime_pm) {
+		pm_runtime_mark_last_busy(ctlr->dev.parent);
+		pm_runtime_put_autosuspend(ctlr->dev.parent);
+	}
+}
+
 /*
  * spi_transfer_one_message - Default implementation of transfer_one_message()
  *
@@ -1240,6 +1248,16 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
 	struct spi_statistics *statm = &ctlr->statistics;
 	struct spi_statistics *stats = &msg->spi->statistics;
 
+	if (ctlr->auto_runtime_pm) {
+		ret = pm_runtime_get_sync(ctlr->dev.parent);
+		if (ret < 0) {
+			pm_runtime_put_noidle(ctlr->dev.parent);
+			dev_err(&ctlr->dev, "Failed to power device: %d\n",
+				ret);
+			return ret;
+		}
+	}
+
 	spi_set_cs(msg->spi, true);
 
 	SPI_STATISTICS_INCREMENT_FIELD(statm, messages);
@@ -1329,6 +1347,8 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
 
 	spi_finalize_current_message(ctlr);
 
+	spi_idle_runtime_pm(ctlr);
+
 	return ret;
 }
 
@@ -1346,14 +1366,6 @@ void spi_finalize_current_transfer(struct spi_controller *ctlr)
 }
 EXPORT_SYMBOL_GPL(spi_finalize_current_transfer);
 
-static void spi_idle_runtime_pm(struct spi_controller *ctlr)
-{
-	if (ctlr->auto_runtime_pm) {
-		pm_runtime_mark_last_busy(ctlr->dev.parent);
-		pm_runtime_put_autosuspend(ctlr->dev.parent);
-	}
-}
-
 /**
  * __spi_pump_messages - function which processes spi message queue
  * @ctlr: controller to process queue for
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ