diff mbox series

[4/8] staging: vchiq_core: Lower indentation of a conditional block

Message ID 20241011072210.494672-5-umang.jain@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series staging: vchiq: Lower indentation at various places | expand

Commit Message

Umang Jain Oct. 11, 2024, 7:22 a.m. UTC
Lower indentation of 'if (bulk->data && service->instance)'
conditional block. This is achieved introducing a early check for
(!bulk->data || !service->instance) and using a goto label 'complete'
if it evaluates to true.

No functional changes intended in this patch.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 .../interface/vchiq_arm/vchiq_core.c          | 61 ++++++++++---------
 1 file changed, 31 insertions(+), 30 deletions(-)

Comments

Stefan Wahren Oct. 11, 2024, 10:54 a.m. UTC | #1
Hi Umang,

Am 11.10.24 um 09:22 schrieb Umang Jain:
> Lower indentation of 'if (bulk->data && service->instance)'
> conditional block. This is achieved introducing a early check for
> (!bulk->data || !service->instance) and using a goto label 'complete'
> if it evaluates to true.
>
> No functional changes intended in this patch.
>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>   .../interface/vchiq_arm/vchiq_core.c          | 61 ++++++++++---------
>   1 file changed, 31 insertions(+), 30 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 15257cf66fa4..b95443043c27 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
> @@ -1326,44 +1326,45 @@ notify_bulks(struct vchiq_service *service, struct vchiq_bulk_queue *queue,
>   		struct vchiq_bulk *bulk =
>   			&queue->bulks[BULK_INDEX(queue->remove)];
>
> +		if (!bulk->data || !service->instance)
> +			goto complete;
> +
>   		/*
>   		 * Only generate callbacks for non-dummy bulk
>   		 * requests, and non-terminated services
>   		 */
> -		if (bulk->data && service->instance) {
> -			if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
> -				if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
> -					VCHIQ_SERVICE_STATS_INC(service, bulk_tx_count);
> -					VCHIQ_SERVICE_STATS_ADD(service, bulk_tx_bytes,
> -								bulk->actual);
> -				} else {
> -					VCHIQ_SERVICE_STATS_INC(service, bulk_rx_count);
> -					VCHIQ_SERVICE_STATS_ADD(service, bulk_rx_bytes,
> -								bulk->actual);
> -				}
> +		if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
> +			if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
> +				VCHIQ_SERVICE_STATS_INC(service, bulk_tx_count);
> +				VCHIQ_SERVICE_STATS_ADD(service, bulk_tx_bytes,
> +							bulk->actual);
>   			} else {
> -				VCHIQ_SERVICE_STATS_INC(service, bulk_aborted_count);
> -			}
> -			if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
> -				struct bulk_waiter *waiter;
> -
> -				spin_lock(&service->state->bulk_waiter_spinlock);
> -				waiter = bulk->userdata;
> -				if (waiter) {
> -					waiter->actual = bulk->actual;
> -					complete(&waiter->event);
> -				}
> -				spin_unlock(&service->state->bulk_waiter_spinlock);
> -			} else if (bulk->mode == VCHIQ_BULK_MODE_CALLBACK) {
> -				enum vchiq_reason reason =
> -						get_bulk_reason(bulk);
> -				status = make_service_callback(service, reason,	NULL,
> -							       bulk->userdata);
> -				if (status == -EAGAIN)
> -					break;
> +				VCHIQ_SERVICE_STATS_INC(service, bulk_rx_count);
> +				VCHIQ_SERVICE_STATS_ADD(service, bulk_rx_bytes,
> +							bulk->actual);
>   			}
> +		} else {
> +			VCHIQ_SERVICE_STATS_INC(service, bulk_aborted_count);
>   		}
> +		if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
> +			struct bulk_waiter *waiter;
>
> +			spin_lock(&service->state->bulk_waiter_spinlock);
> +			waiter = bulk->userdata;
> +			if (waiter) {
> +				waiter->actual = bulk->actual;
> +				complete(&waiter->event);
> +			}
> +			spin_unlock(&service->state->bulk_waiter_spinlock);
> +		} else if (bulk->mode == VCHIQ_BULK_MODE_CALLBACK) {
> +			enum vchiq_reason reason =
> +					get_bulk_reason(bulk);
> +			status = make_service_callback(service, reason,	NULL,
> +						       bulk->userdata);
> +			if (status == -EAGAIN)
> +				break;
> +		}
> +complete:
I would consider goto labels within a while loop as error prone and
ugly. Maybe moving the enclosing code into a separate function would be
a nicer approach?

Regards
>   		queue->remove++;
>   		complete(&service->bulk_remove_event);
>   	}
diff mbox series

Patch

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 15257cf66fa4..b95443043c27 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -1326,44 +1326,45 @@  notify_bulks(struct vchiq_service *service, struct vchiq_bulk_queue *queue,
 		struct vchiq_bulk *bulk =
 			&queue->bulks[BULK_INDEX(queue->remove)];
 
+		if (!bulk->data || !service->instance)
+			goto complete;
+
 		/*
 		 * Only generate callbacks for non-dummy bulk
 		 * requests, and non-terminated services
 		 */
-		if (bulk->data && service->instance) {
-			if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
-				if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
-					VCHIQ_SERVICE_STATS_INC(service, bulk_tx_count);
-					VCHIQ_SERVICE_STATS_ADD(service, bulk_tx_bytes,
-								bulk->actual);
-				} else {
-					VCHIQ_SERVICE_STATS_INC(service, bulk_rx_count);
-					VCHIQ_SERVICE_STATS_ADD(service, bulk_rx_bytes,
-								bulk->actual);
-				}
+		if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
+			if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
+				VCHIQ_SERVICE_STATS_INC(service, bulk_tx_count);
+				VCHIQ_SERVICE_STATS_ADD(service, bulk_tx_bytes,
+							bulk->actual);
 			} else {
-				VCHIQ_SERVICE_STATS_INC(service, bulk_aborted_count);
-			}
-			if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
-				struct bulk_waiter *waiter;
-
-				spin_lock(&service->state->bulk_waiter_spinlock);
-				waiter = bulk->userdata;
-				if (waiter) {
-					waiter->actual = bulk->actual;
-					complete(&waiter->event);
-				}
-				spin_unlock(&service->state->bulk_waiter_spinlock);
-			} else if (bulk->mode == VCHIQ_BULK_MODE_CALLBACK) {
-				enum vchiq_reason reason =
-						get_bulk_reason(bulk);
-				status = make_service_callback(service, reason,	NULL,
-							       bulk->userdata);
-				if (status == -EAGAIN)
-					break;
+				VCHIQ_SERVICE_STATS_INC(service, bulk_rx_count);
+				VCHIQ_SERVICE_STATS_ADD(service, bulk_rx_bytes,
+							bulk->actual);
 			}
+		} else {
+			VCHIQ_SERVICE_STATS_INC(service, bulk_aborted_count);
 		}
+		if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
+			struct bulk_waiter *waiter;
 
+			spin_lock(&service->state->bulk_waiter_spinlock);
+			waiter = bulk->userdata;
+			if (waiter) {
+				waiter->actual = bulk->actual;
+				complete(&waiter->event);
+			}
+			spin_unlock(&service->state->bulk_waiter_spinlock);
+		} else if (bulk->mode == VCHIQ_BULK_MODE_CALLBACK) {
+			enum vchiq_reason reason =
+					get_bulk_reason(bulk);
+			status = make_service_callback(service, reason,	NULL,
+						       bulk->userdata);
+			if (status == -EAGAIN)
+				break;
+		}
+complete:
 		queue->remove++;
 		complete(&service->bulk_remove_event);
 	}