linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Stefan Wahren <stefan.wahren@i2se.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Nicolas Saenz Julienne <nsaenz@kernel.org>
Cc: linux-staging@lists.linux.dev, Stefan Wahren <stefan.wahren@i2se.com>
Subject: [PATCH 16/16] staging: vchiq_core: introduce handle_poll
Date: Thu,  3 Jun 2021 17:50:05 +0200	[thread overview]
Message-ID: <1622735405-9980-17-git-send-email-stefan.wahren@i2se.com> (raw)
In-Reply-To: <1622735405-9980-1-git-send-email-stefan.wahren@i2se.com>

The function slot_handler_func() has very deep indentations. Moving the
poll handling into separate function could improve the readability.
Use the return value to keep the poll_needed handling at the same place.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
 .../vc04_services/interface/vchiq_arm/vchiq_core.c | 92 ++++++++++++----------
 1 file changed, 52 insertions(+), 40 deletions(-)

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
index a2a2472..4f43e42 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -1992,6 +1992,56 @@ parse_rx_slots(struct vchiq_state *state)
 	}
 }
 
+/**
+ * handle_poll() - handle service polling and other rare conditions
+ * @state:  vchiq state struct
+ *
+ * Context: Process context
+ *
+ * Return:
+ * * 0        - poll handled successful
+ * * -EAGAIN  - retry later
+ */
+static int
+handle_poll(struct vchiq_state *state)
+{
+	switch (state->conn_state) {
+	case VCHIQ_CONNSTATE_CONNECTED:
+		/* Poll the services as requested */
+		poll_services(state);
+		break;
+
+	case VCHIQ_CONNSTATE_PAUSING:
+		if (queue_message(state, NULL, MAKE_PAUSE, NULL, NULL, 0,
+				  QMFLAGS_NO_MUTEX_UNLOCK) != VCHIQ_RETRY) {
+			vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSE_SENT);
+		} else {
+			/* Retry later */
+			return -EAGAIN;
+		}
+		break;
+
+	case VCHIQ_CONNSTATE_RESUMING:
+		if (queue_message(state, NULL, MAKE_RESUME, NULL, NULL, 0,
+				  QMFLAGS_NO_MUTEX_LOCK) != VCHIQ_RETRY) {
+			vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
+		} else {
+			/*
+			 * This should really be impossible,
+			 * since the PAUSE should have flushed
+			 * through outstanding messages.
+			 */
+			vchiq_log_error(vchiq_core_log_level,
+				"Failed to send RESUME message");
+		}
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
 /* Called by the slot handler thread */
 static int
 slot_handler_func(void *v)
@@ -2010,52 +2060,14 @@ slot_handler_func(void *v)
 
 		DEBUG_TRACE(SLOT_HANDLER_LINE);
 		if (state->poll_needed) {
-
 			state->poll_needed = 0;
 
 			/*
 			 * Handle service polling and other rare conditions here
 			 * out of the mainline code
 			 */
-			switch (state->conn_state) {
-			case VCHIQ_CONNSTATE_CONNECTED:
-				/* Poll the services as requested */
-				poll_services(state);
-				break;
-
-			case VCHIQ_CONNSTATE_PAUSING:
-				if (queue_message(state, NULL, MAKE_PAUSE,
-					NULL, NULL, 0,
-					QMFLAGS_NO_MUTEX_UNLOCK)
-				    != VCHIQ_RETRY) {
-					vchiq_set_conn_state(state,
-						VCHIQ_CONNSTATE_PAUSE_SENT);
-				} else {
-					/* Retry later */
-					state->poll_needed = 1;
-				}
-				break;
-
-			case VCHIQ_CONNSTATE_RESUMING:
-				if (queue_message(state, NULL, MAKE_RESUME,
-					NULL, NULL, 0, QMFLAGS_NO_MUTEX_LOCK)
-					!= VCHIQ_RETRY) {
-					vchiq_set_conn_state(state,
-						VCHIQ_CONNSTATE_CONNECTED);
-				} else {
-					/*
-					 * This should really be impossible,
-					 * since the PAUSE should have flushed
-					 * through outstanding messages.
-					 */
-					vchiq_log_error(vchiq_core_log_level,
-						"Failed to send RESUME message");
-				}
-				break;
-			default:
-				break;
-			}
-
+			if (handle_poll(state) == -EAGAIN)
+				state->poll_needed = 1;
 		}
 
 		DEBUG_TRACE(SLOT_HANDLER_LINE);
-- 
2.7.4


      parent reply	other threads:[~2021-06-03 15:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03 15:49 [PATCH 00/16] staging: vchiq_arm: code clean-up part 3 Stefan Wahren
2021-06-03 15:49 ` [PATCH 01/16] staging: vchiq_core: fix logic in poll_services_of_group Stefan Wahren
2021-06-03 15:49 ` [PATCH 02/16] staging: vchiq_arm: introduce free_bulk_waiter Stefan Wahren
2021-06-03 15:49 ` [PATCH 03/16] staging: vchiq_core: move internals to C source Stefan Wahren
2021-06-03 15:49 ` [PATCH 04/16] staging: vchiq_core: get the rid of IS_POW2 Stefan Wahren
2021-06-03 15:49 ` [PATCH 05/16] staging: vchiq_core: get the rid of vchiq_static_assert Stefan Wahren
2021-06-03 15:49 ` [PATCH 06/16] staging: vchiq_core: put spaces around operators Stefan Wahren
2021-06-03 15:49 ` [PATCH 07/16] staging: vchiq_core: avoid precedence issues Stefan Wahren
2021-06-03 15:49 ` [PATCH 08/16] staging: vchiq_core: use define for message type shift Stefan Wahren
2021-06-03 15:49 ` [PATCH 09/16] staging: vchiq_core: introduce message specific make macros Stefan Wahren
2021-06-03 15:49 ` [PATCH 10/16] staging: vchiq_core: simplify WARN_ON conditions Stefan Wahren
2021-06-03 15:50 ` [PATCH 11/16] staging: vchiq_arm: tidy up service function naming Stefan Wahren
2021-06-03 15:50 ` [PATCH 12/16] staging: vchiq_core: introduce process_free_data_message Stefan Wahren
2021-06-03 15:50 ` [PATCH 13/16] staging: vchiq_core: reduce indentation in parse_open Stefan Wahren
2021-06-03 15:50 ` [PATCH 14/16] staging: vchiq_core: store message id in local variable Stefan Wahren
2021-06-03 15:50 ` [PATCH 15/16] staging: vchiq_connected: move EXPORT_SYMBOL below the right function Stefan Wahren
2021-06-03 15:50 ` Stefan Wahren [this message]

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=1622735405-9980-17-git-send-email-stefan.wahren@i2se.com \
    --to=stefan.wahren@i2se.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=nsaenz@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).