Commit 001943e8 authored by Narcisa Ana Maria Vasile's avatar Narcisa Ana Maria Vasile Committed by Greg Kroah-Hartman

staging: vc04_services: Refactor conditionals

Refactor conditionals to reduce one level of indentation and improve
code readability.
Signed-off-by: default avatarNarcisa Ana Maria Vasile <narcisaanamaria12@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 41831482
...@@ -2574,129 +2574,125 @@ vchiq_add_service_internal(VCHIQ_STATE_T *state, ...@@ -2574,129 +2574,125 @@ vchiq_add_service_internal(VCHIQ_STATE_T *state,
VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term) VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
{ {
VCHIQ_SERVICE_T *service; VCHIQ_SERVICE_T *service;
VCHIQ_SERVICE_T **pservice = NULL;
VCHIQ_SERVICE_QUOTA_T *service_quota;
int i;
service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL); service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
if (service) { if (!service)
service->base.fourcc = params->fourcc; return service;
service->base.callback = params->callback;
service->base.userdata = params->userdata; service->base.fourcc = params->fourcc;
service->handle = VCHIQ_SERVICE_HANDLE_INVALID; service->base.callback = params->callback;
service->ref_count = 1; service->base.userdata = params->userdata;
service->srvstate = VCHIQ_SRVSTATE_FREE; service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
service->userdata_term = userdata_term; service->ref_count = 1;
service->localport = VCHIQ_PORT_FREE; service->srvstate = VCHIQ_SRVSTATE_FREE;
service->remoteport = VCHIQ_PORT_FREE; service->userdata_term = userdata_term;
service->localport = VCHIQ_PORT_FREE;
service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ? service->remoteport = VCHIQ_PORT_FREE;
VCHIQ_FOURCC_INVALID : params->fourcc;
service->client_id = 0; service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
service->auto_close = 1; VCHIQ_FOURCC_INVALID : params->fourcc;
service->sync = 0; service->client_id = 0;
service->closing = 0; service->auto_close = 1;
service->trace = 0; service->sync = 0;
atomic_set(&service->poll_flags, 0); service->closing = 0;
service->version = params->version; service->trace = 0;
service->version_min = params->version_min; atomic_set(&service->poll_flags, 0);
service->state = state; service->version = params->version;
service->instance = instance; service->version_min = params->version_min;
service->service_use_count = 0; service->state = state;
init_bulk_queue(&service->bulk_tx); service->instance = instance;
init_bulk_queue(&service->bulk_rx); service->service_use_count = 0;
sema_init(&service->remove_event, 0); init_bulk_queue(&service->bulk_tx);
sema_init(&service->bulk_remove_event, 0); init_bulk_queue(&service->bulk_rx);
mutex_init(&service->bulk_mutex); sema_init(&service->remove_event, 0);
memset(&service->stats, 0, sizeof(service->stats)); sema_init(&service->bulk_remove_event, 0);
} mutex_init(&service->bulk_mutex);
memset(&service->stats, 0, sizeof(service->stats));
if (service) {
VCHIQ_SERVICE_T **pservice = NULL; /* Although it is perfectly possible to use service_spinlock
int i; ** to protect the creation of services, it is overkill as it
** disables interrupts while the array is searched.
/* Although it is perfectly possible to use service_spinlock ** The only danger is of another thread trying to create a
** to protect the creation of services, it is overkill as it ** service - service deletion is safe.
** disables interrupts while the array is searched. ** Therefore it is preferable to use state->mutex which,
** The only danger is of another thread trying to create a ** although slower to claim, doesn't block interrupts while
** service - service deletion is safe. ** it is held.
** Therefore it is preferable to use state->mutex which, */
** although slower to claim, doesn't block interrupts while
** it is held. mutex_lock(&state->mutex);
*/
/* Prepare to use a previously unused service */
mutex_lock(&state->mutex); if (state->unused_service < VCHIQ_MAX_SERVICES)
pservice = &state->services[state->unused_service];
/* Prepare to use a previously unused service */
if (state->unused_service < VCHIQ_MAX_SERVICES) if (srvstate == VCHIQ_SRVSTATE_OPENING) {
pservice = &state->services[state->unused_service]; for (i = 0; i < state->unused_service; i++) {
VCHIQ_SERVICE_T *srv = state->services[i];
if (srvstate == VCHIQ_SRVSTATE_OPENING) {
for (i = 0; i < state->unused_service; i++) { if (!srv) {
VCHIQ_SERVICE_T *srv = state->services[i]; pservice = &state->services[i];
break;
if (!srv) {
pservice = &state->services[i];
break;
}
} }
} else { }
for (i = (state->unused_service - 1); i >= 0; i--) { } else {
VCHIQ_SERVICE_T *srv = state->services[i]; for (i = (state->unused_service - 1); i >= 0; i--) {
VCHIQ_SERVICE_T *srv = state->services[i];
if (!srv)
pservice = &state->services[i]; if (!srv)
else if ((srv->public_fourcc == params->fourcc) pservice = &state->services[i];
&& ((srv->instance != instance) || else if ((srv->public_fourcc == params->fourcc)
(srv->base.callback != && ((srv->instance != instance) ||
params->callback))) { (srv->base.callback !=
/* There is another server using this params->callback))) {
** fourcc which doesn't match. */ /* There is another server using this
pservice = NULL; ** fourcc which doesn't match. */
break; pservice = NULL;
} break;
} }
} }
}
if (pservice) { if (pservice) {
service->localport = (pservice - state->services); service->localport = (pservice - state->services);
if (!handle_seq) if (!handle_seq)
handle_seq = VCHIQ_MAX_STATES * handle_seq = VCHIQ_MAX_STATES *
VCHIQ_MAX_SERVICES; VCHIQ_MAX_SERVICES;
service->handle = handle_seq | service->handle = handle_seq |
(state->id * VCHIQ_MAX_SERVICES) | (state->id * VCHIQ_MAX_SERVICES) |
service->localport; service->localport;
handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES; handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
*pservice = service; *pservice = service;
if (pservice == &state->services[state->unused_service]) if (pservice == &state->services[state->unused_service])
state->unused_service++; state->unused_service++;
} }
mutex_unlock(&state->mutex); mutex_unlock(&state->mutex);
if (!pservice) { if (!pservice) {
kfree(service); kfree(service);
service = NULL; service = NULL;
}
} }
if (service) { service_quota = &state->service_quotas[service->localport];
VCHIQ_SERVICE_QUOTA_T *service_quota = service_quota->slot_quota = state->default_slot_quota;
&state->service_quotas[service->localport]; service_quota->message_quota = state->default_message_quota;
service_quota->slot_quota = state->default_slot_quota; if (service_quota->slot_use_count == 0)
service_quota->message_quota = state->default_message_quota; service_quota->previous_tx_index =
if (service_quota->slot_use_count == 0) SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
service_quota->previous_tx_index = - 1;
SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
- 1; /* Bring this service online */
vchiq_set_service_state(service, srvstate);
/* Bring this service online */
vchiq_set_service_state(service, srvstate); vchiq_log_info(vchiq_core_msg_log_level,
"%s Service %c%c%c%c SrcPort:%d",
vchiq_log_info(vchiq_core_msg_log_level, (srvstate == VCHIQ_SRVSTATE_OPENING)
"%s Service %c%c%c%c SrcPort:%d", ? "Open" : "Add",
(srvstate == VCHIQ_SRVSTATE_OPENING) VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
? "Open" : "Add", service->localport);
VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
service->localport);
}
/* Don't unlock the service - leave it with a ref_count of 1. */ /* Don't unlock the service - leave it with a ref_count of 1. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment