All of lore.kernel.org
 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 04/10] staging: vchiq_core: Exit early in 2 functions
Date: Sun, 11 Apr 2021 20:11:34 +0200	[thread overview]
Message-ID: <1618164700-21150-5-git-send-email-stefan.wahren@i2se.com> (raw)
In-Reply-To: <1618164700-21150-1-git-send-email-stefan.wahren@i2se.com>

Exit early allow us to reduce the indention in vchiq_open_service_internal()
and vchiq_set_service_option(). Btw we can avoid the multi-line assignments
of quota.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
 .../vc04_services/interface/vchiq_arm/vchiq_core.c | 151 ++++++++++-----------
 1 file changed, 74 insertions(+), 77 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 835f2a5..e67ba54 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -2525,24 +2525,27 @@ vchiq_open_service_internal(struct vchiq_service *service, int client_id)
 			       &payload,
 			       sizeof(payload),
 			       QMFLAGS_IS_BLOCKING);
-	if (status == VCHIQ_SUCCESS) {
-		/* Wait for the ACK/NAK */
-		if (wait_for_completion_interruptible(&service->remove_event)) {
-			status = VCHIQ_RETRY;
-			vchiq_release_service_internal(service);
-		} else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
-			   (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
-			if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
-				vchiq_log_error(vchiq_core_log_level,
-						"%d: osi - srvstate = %s (ref %u)",
-						service->state->id,
-						srvstate_names[service->srvstate],
-						kref_read(&service->ref_count));
-			status = VCHIQ_ERROR;
-			VCHIQ_SERVICE_STATS_INC(service, error_count);
-			vchiq_release_service_internal(service);
-		}
+
+	if (status != VCHIQ_SUCCESS)
+		return status;
+
+	/* Wait for the ACK/NAK */
+	if (wait_for_completion_interruptible(&service->remove_event)) {
+		status = VCHIQ_RETRY;
+		vchiq_release_service_internal(service);
+	} else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
+		   (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
+		if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
+			vchiq_log_error(vchiq_core_log_level,
+					"%d: osi - srvstate = %s (ref %u)",
+					service->state->id,
+					srvstate_names[service->srvstate],
+					kref_read(&service->ref_count));
+		status = VCHIQ_ERROR;
+		VCHIQ_SERVICE_STATS_INC(service, error_count);
+		vchiq_release_service_internal(service);
 	}
+
 	return status;
 }
 
@@ -3359,74 +3362,68 @@ vchiq_set_service_option(unsigned int handle,
 	enum vchiq_status status = VCHIQ_ERROR;
 	struct vchiq_service_quota *quota;
 
-	if (service) {
-		switch (option) {
-		case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
-			service->auto_close = value;
-			status = VCHIQ_SUCCESS;
-			break;
+	if (!service)
+		return VCHIQ_ERROR;
+
+	switch (option) {
+	case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
+		service->auto_close = value;
+		status = VCHIQ_SUCCESS;
+		break;
 
-		case VCHIQ_SERVICE_OPTION_SLOT_QUOTA:
-			quota = &service->state->service_quotas[
-					service->localport];
-			if (value == 0)
-				value = service->state->default_slot_quota;
+	case VCHIQ_SERVICE_OPTION_SLOT_QUOTA:
+		quota = &service->state->service_quotas[service->localport];
+		if (value == 0)
+			value = service->state->default_slot_quota;
+		if ((value >= quota->slot_use_count) &&
+		    (value < (unsigned short)~0)) {
+			quota->slot_quota = value;
 			if ((value >= quota->slot_use_count) &&
-				 (value < (unsigned short)~0)) {
-				quota->slot_quota = value;
-				if ((value >= quota->slot_use_count) &&
-					(quota->message_quota >=
-					 quota->message_use_count)) {
-					/*
-					 * Signal the service that it may have
-					 * dropped below its quota
-					 */
-					complete(&quota->quota_event);
-				}
-				status = VCHIQ_SUCCESS;
-			}
-			break;
+			    (quota->message_quota >= quota->message_use_count))
+				/*
+				 * Signal the service that it may have
+				 * dropped below its quota
+				 */
+				complete(&quota->quota_event);
+			status = VCHIQ_SUCCESS;
+		}
+		break;
 
-		case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA:
-			quota = &service->state->service_quotas[
-					service->localport];
-			if (value == 0)
-				value = service->state->default_message_quota;
+	case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA:
+		quota = &service->state->service_quotas[service->localport];
+		if (value == 0)
+			value = service->state->default_message_quota;
+		if ((value >= quota->message_use_count) &&
+		    (value < (unsigned short)~0)) {
+			quota->message_quota = value;
 			if ((value >= quota->message_use_count) &&
-				 (value < (unsigned short)~0)) {
-				quota->message_quota = value;
-				if ((value >=
-					quota->message_use_count) &&
-					(quota->slot_quota >=
-					quota->slot_use_count))
-					/*
-					 * Signal the service that it may have
-					 * dropped below its quota
-					 */
-					complete(&quota->quota_event);
-				status = VCHIQ_SUCCESS;
-			}
-			break;
-
-		case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
-			if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
-				(service->srvstate ==
-				VCHIQ_SRVSTATE_LISTENING)) {
-				service->sync = value;
-				status = VCHIQ_SUCCESS;
-			}
-			break;
-
-		case VCHIQ_SERVICE_OPTION_TRACE:
-			service->trace = value;
+			    (quota->slot_quota >= quota->slot_use_count))
+				/*
+				 * Signal the service that it may have
+				 * dropped below its quota
+				 */
+				complete(&quota->quota_event);
 			status = VCHIQ_SUCCESS;
-			break;
+		}
+		break;
 
-		default:
-			break;
+	case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
+		if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
+		    (service->srvstate == VCHIQ_SRVSTATE_LISTENING)) {
+			service->sync = value;
+			status = VCHIQ_SUCCESS;
 		}
-		unlock_service(service);
+		break;
+
+	case VCHIQ_SERVICE_OPTION_TRACE:
+		service->trace = value;
+		status = VCHIQ_SUCCESS;
+		break;
+
+	default:
+		break;
 	}
+	unlock_service(service);
 
 	return status;
 }
-- 
2.7.4


  parent reply	other threads:[~2021-04-11 18:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-11 18:11 [PATCH 00/10] staging: vchiq_core: improve code readability Stefan Wahren
2021-04-11 18:11 ` [PATCH 01/10] staging: vchiq_core: Simplify vchiq_send_remote_use* Stefan Wahren
2021-04-11 18:11 ` [PATCH 02/10] staging: vchiq_core: Shorten var name for service quota Stefan Wahren
2021-04-11 18:11 ` [PATCH 03/10] staging: vchiq_core: Get the rid off curly braces around cases Stefan Wahren
2021-04-11 18:11 ` Stefan Wahren [this message]
2021-04-11 18:11 ` [PATCH 05/10] staging: vchiq_core: introduce service skip Stefan Wahren
2021-04-11 18:11 ` [PATCH 06/10] staging: vchiq_core: improve readability of request_poll Stefan Wahren
2021-04-11 18:11 ` [PATCH 07/10] staging: vchiq_core: use BITSET_WORD macro Stefan Wahren
2021-04-11 18:11 ` [PATCH 08/10] staging: vchiq_core: introduce SLOT_QUEUE_INDEX_FROM_POS_MASKED Stefan Wahren
2021-04-11 18:11 ` [PATCH 09/10] staging: vchiq_core: fix if alignments Stefan Wahren
2021-04-11 18:11 ` [PATCH 10/10] staging: vchiq_core: split exit conditions Stefan Wahren

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=1618164700-21150-5-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.