Skip to content

Commit 504b0e3

Browse files
lategoodbyegregkh
authored andcommitted
staging: vchiq_arm: Reduce indentation of service_callback
The service_callback has 5 levels of indentation, which makes it hard to read. Reduce this by splitting the code in a new function service_single_message() as suggested by Laurent Pinchart. Signed-off-by: Stefan Wahren <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7852f73 commit 504b0e3

File tree

1 file changed

+43
-29
lines changed
  • drivers/staging/vc04_services/interface/vchiq_arm

1 file changed

+43
-29
lines changed

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,43 @@ add_completion(struct vchiq_instance *instance, enum vchiq_reason reason,
10551055
return 0;
10561056
}
10571057

1058+
static int
1059+
service_single_message(struct vchiq_instance *instance,
1060+
enum vchiq_reason reason,
1061+
struct vchiq_service *service, void *bulk_userdata)
1062+
{
1063+
struct user_service *user_service;
1064+
1065+
user_service = (struct user_service *)service->base.userdata;
1066+
1067+
dev_dbg(service->state->dev, "arm: msg queue full\n");
1068+
/*
1069+
* If there is no MESSAGE_AVAILABLE in the completion
1070+
* queue, add one
1071+
*/
1072+
if ((user_service->message_available_pos -
1073+
instance->completion_remove) < 0) {
1074+
int ret;
1075+
1076+
dev_dbg(instance->state->dev,
1077+
"arm: Inserting extra MESSAGE_AVAILABLE\n");
1078+
ret = add_completion(instance, reason, NULL, user_service,
1079+
bulk_userdata);
1080+
if (ret)
1081+
return ret;
1082+
}
1083+
1084+
if (wait_for_completion_interruptible(&user_service->remove_event)) {
1085+
dev_dbg(instance->state->dev, "arm: interrupted\n");
1086+
return -EAGAIN;
1087+
} else if (instance->closing) {
1088+
dev_dbg(instance->state->dev, "arm: closing\n");
1089+
return -EINVAL;
1090+
}
1091+
1092+
return 0;
1093+
}
1094+
10581095
int
10591096
service_callback(struct vchiq_instance *instance, enum vchiq_reason reason,
10601097
struct vchiq_header *header, unsigned int handle, void *bulk_userdata)
@@ -1104,41 +1141,18 @@ service_callback(struct vchiq_instance *instance, enum vchiq_reason reason,
11041141
spin_lock(&service->state->msg_queue_spinlock);
11051142
while (user_service->msg_insert ==
11061143
(user_service->msg_remove + MSG_QUEUE_SIZE)) {
1144+
int ret;
1145+
11071146
spin_unlock(&service->state->msg_queue_spinlock);
11081147
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
11091148
DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
1110-
dev_dbg(service->state->dev, "arm: msg queue full\n");
1111-
/*
1112-
* If there is no MESSAGE_AVAILABLE in the completion
1113-
* queue, add one
1114-
*/
1115-
if ((user_service->message_available_pos -
1116-
instance->completion_remove) < 0) {
1117-
int ret;
1118-
1119-
dev_dbg(instance->state->dev,
1120-
"arm: Inserting extra MESSAGE_AVAILABLE\n");
1121-
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
1122-
ret = add_completion(instance, reason, NULL, user_service,
1123-
bulk_userdata);
1124-
if (ret) {
1125-
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
1126-
vchiq_service_put(service);
1127-
return ret;
1128-
}
1129-
}
11301149

1131-
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
1132-
if (wait_for_completion_interruptible(&user_service->remove_event)) {
1133-
dev_dbg(instance->state->dev, "arm: interrupted\n");
1134-
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
1135-
vchiq_service_put(service);
1136-
return -EAGAIN;
1137-
} else if (instance->closing) {
1138-
dev_dbg(instance->state->dev, "arm: closing\n");
1150+
ret = service_single_message(instance, reason,
1151+
service, bulk_userdata);
1152+
if (ret) {
11391153
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
11401154
vchiq_service_put(service);
1141-
return -EINVAL;
1155+
return ret;
11421156
}
11431157
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
11441158
spin_lock(&service->state->msg_queue_spinlock);

0 commit comments

Comments
 (0)