Thread (44 messages) 44 messages, 5 authors, 2022-08-31
STALE1405d

[PATCH 06/16] fpga: machxo2-spi: factor out status check for readability

From: Johannes Zink <hidden>
Date: 2022-08-25 14:20:41
Also in: linux-fpga
Subsystem: fpga manager framework, the rest · Maintainers: Moritz Fischer, Xu Yilun, Linus Torvalds

We have the same sequence at two different places, so factor it out
into a helper to improve readability.

Signed-off-by: Johannes Zink <redacted>
---
 drivers/fpga/machxo2-spi.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/fpga/machxo2-spi.c b/drivers/fpga/machxo2-spi.c
index 39dd62359821..5e12612c7289 100644
--- a/drivers/fpga/machxo2-spi.c
+++ b/drivers/fpga/machxo2-spi.c
@@ -167,14 +167,19 @@ static int machxo2_cleanup(struct fpga_manager *mgr)
 	return ret;
 }
 
+static bool machxo2_status_done(unsigned long status)
+{
+	return !test_bit(BUSY, &status) && test_bit(DONE, &status) &&
+		get_err(&status) == ENOERR;
+}
+
 static enum fpga_mgr_states machxo2_spi_state(struct fpga_manager *mgr)
 {
 	struct spi_device *spi = mgr->priv;
 	unsigned long status;
 
 	get_status(spi, &status);
-	if (!test_bit(BUSY, &status) && test_bit(DONE, &status) &&
-	    get_err(&status) == ENOERR)
+	if (machxo2_status_done(status))
 		return FPGA_MGR_STATE_OPERATING;
 
 	return FPGA_MGR_STATE_UNKNOWN;
@@ -329,8 +334,7 @@ static int machxo2_write_complete(struct fpga_manager *mgr,
 		/* check refresh status */
 		get_status(spi, &status);
 		dump_status_reg(&status);
-		if (!test_bit(BUSY, &status) && test_bit(DONE, &status) &&
-		    get_err(&status) == ENOERR)
+		if (machxo2_status_done(status))
 			break;
 		if (++refreshloop == MACHXO2_MAX_REFRESH_LOOP) {
 			machxo2_cleanup(mgr);
-- 
2.30.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help