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 03/10] staging: vchiq_core: introduce get_bulk_reason
Date: Thu, 22 Apr 2021 22:07:49 +0200	[thread overview]
Message-ID: <1619122076-31785-4-git-send-email-stefan.wahren@i2se.com> (raw)
In-Reply-To: <1619122076-31785-1-git-send-email-stefan.wahren@i2se.com>

Nesting multiple ternary operators over multiple lines isn't easy to
read. Move this logic into a separate inline function.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
 .../vc04_services/interface/vchiq_arm/vchiq_core.c | 35 ++++++++++++++--------
 1 file changed, 22 insertions(+), 13 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 8a1e6f5..3a72c36 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -1226,6 +1226,22 @@ release_slot(struct vchiq_state *state, struct vchiq_slot_info *slot_info,
 	mutex_unlock(&state->recycle_mutex);
 }
 
+static inline enum vchiq_reason
+get_bulk_reason(struct vchiq_bulk *bulk)
+{
+	if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
+		if (bulk->actual == VCHIQ_BULK_ACTUAL_ABORTED)
+			return VCHIQ_BULK_TRANSMIT_ABORTED;
+
+		return VCHIQ_BULK_TRANSMIT_DONE;
+	}
+
+	if (bulk->actual == VCHIQ_BULK_ACTUAL_ABORTED)
+		return VCHIQ_BULK_RECEIVE_ABORTED;
+
+	return VCHIQ_BULK_RECEIVE_DONE;
+}
+
 /* Called by the slot handler - don't hold the bulk mutex */
 static enum vchiq_status
 notify_bulks(struct vchiq_service *service, struct vchiq_bulk_queue *queue,
@@ -1281,16 +1297,8 @@ notify_bulks(struct vchiq_service *service, struct vchiq_bulk_queue *queue,
 					spin_unlock(&bulk_waiter_spinlock);
 				} else if (bulk->mode ==
 					VCHIQ_BULK_MODE_CALLBACK) {
-					enum vchiq_reason reason = (bulk->dir ==
-						VCHIQ_BULK_TRANSMIT) ?
-						((bulk->actual ==
-						VCHIQ_BULK_ACTUAL_ABORTED) ?
-						VCHIQ_BULK_TRANSMIT_ABORTED :
-						VCHIQ_BULK_TRANSMIT_DONE) :
-						((bulk->actual ==
-						VCHIQ_BULK_ACTUAL_ABORTED) ?
-						VCHIQ_BULK_RECEIVE_ABORTED :
-						VCHIQ_BULK_RECEIVE_DONE);
+					enum vchiq_reason reason =
+							get_bulk_reason(bulk);
 					status = make_service_callback(service,
 						reason,	NULL, bulk->userdata);
 					if (status == VCHIQ_RETRY)
@@ -2622,9 +2630,10 @@ do_abort_bulks(struct vchiq_service *service)
 	mutex_unlock(&service->bulk_mutex);
 
 	status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
-	if (status == VCHIQ_SUCCESS)
-		status = notify_bulks(service, &service->bulk_rx,
-			0/*!retry_poll*/);
+	if (status != VCHIQ_SUCCESS)
+		return 0;
+
+	status = notify_bulks(service, &service->bulk_rx, 0/*!retry_poll*/);
 	return (status == VCHIQ_SUCCESS);
 }
 
-- 
2.7.4


  parent reply	other threads:[~2021-04-22 20:08 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22 20:07 [PATCH 00/10] staging: vchiq_arm: address TODO list Stefan Wahren
2021-04-22 20:07 ` [PATCH 01/10] staging: vchiq_arm: avoid crashing the kernel Stefan Wahren
2021-04-24  9:49   ` nicolas saenz julienne
2021-04-22 20:07 ` [PATCH 02/10] staging: vchiq_core: break early in vchiq_close_service_internal Stefan Wahren
2021-04-23  9:10   ` nicolas saenz julienne
2021-04-22 20:07 ` Stefan Wahren [this message]
2021-04-23  7:23   ` [PATCH 03/10] staging: vchiq_core: introduce get_bulk_reason Fabio Aiuto
2021-04-23 10:54     ` Stefan Wahren
2021-04-23  9:17   ` nicolassaenzj
2021-04-22 20:07 ` [PATCH 04/10] staging: vchiq_core: Drop unnecessary check in notify_bulks Stefan Wahren
2021-04-23  9:22   ` nicolassaenzj
2021-04-22 20:07 ` [PATCH 05/10] staging: vchiq_arm: drop return value of vchiq_arm_init_state Stefan Wahren
2021-04-23  9:28   ` nicolas saenz julienne
2021-04-22 20:07 ` [PATCH 06/10] staging: vchiq_2835_arm: drop enum vchiq_status Stefan Wahren
2021-04-23  9:30   ` nicolas saenz julienne
2021-04-22 20:07 ` [PATCH 07/10] staging: vchiq_arm: drop enum vchiq_status from vchiq_*_internal Stefan Wahren
2021-04-23  9:34   ` nicolas saenz julienne
2021-04-22 20:07 ` [PATCH 08/10] staging: vchiq_core: drop vchiq_status from vchiq_set_service_option Stefan Wahren
2021-04-23  9:59   ` nicolas saenz julienne
2021-04-23 11:03     ` Stefan Wahren
2021-04-24  9:34       ` nicolas saenz julienne
2021-04-22 20:07 ` [PATCH 09/10] staging: vchiq_core: drop vchiq_status from vchiq_initialise Stefan Wahren
2021-04-23 10:02   ` nicolas saenz julienne
2021-04-22 20:07 ` [PATCH 10/10] staging: vchiq_core: drop vchiq_status from vchiq_init_state Stefan Wahren
2021-04-23 10:04   ` nicolas saenz julienne

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=1619122076-31785-4-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.