Skip to content

Commit

Permalink
staging: vchiq_core: Bail out if service is NULL
Browse files Browse the repository at this point in the history
In the unlikely case that service is NULL we should bail out instead
of calling BUG_ON(). The other BUG_ON calls will be fixed in separate
patches.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Stefan Wahren authored and Greg Kroah-Hartman committed May 29, 2017
1 parent 00b9d0f commit 6b8db0b
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,33 @@ void
lock_service(VCHIQ_SERVICE_T *service)
{
spin_lock(&service_spinlock);
BUG_ON(!service || (service->ref_count == 0));
if (service)
WARN_ON(!service);
if (service) {
BUG_ON(service->ref_count == 0);
service->ref_count++;
}
spin_unlock(&service_spinlock);
}

void
unlock_service(VCHIQ_SERVICE_T *service)
{
spin_lock(&service_spinlock);
BUG_ON(!service || (service->ref_count == 0));
if (service && service->ref_count) {
service->ref_count--;
if (!service->ref_count) {
VCHIQ_STATE_T *state = service->state;

BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
state->services[service->localport] = NULL;
} else
service = NULL;
if (!service) {
WARN(1, "%s: service is NULL\n", __func__);
goto unlock;
}
BUG_ON(service->ref_count == 0);
service->ref_count--;
if (!service->ref_count) {
VCHIQ_STATE_T *state = service->state;

BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
state->services[service->localport] = NULL;
} else {
service = NULL;
}
unlock:
spin_unlock(&service_spinlock);

if (service && service->userdata_term)
Expand Down Expand Up @@ -822,7 +828,12 @@ queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
if (type == VCHIQ_MSG_DATA) {
int tx_end_index;

BUG_ON(!service);
if (!service) {
WARN(1, "%s: service is NULL\n", __func__);
mutex_unlock(&state->slot_mutex);
return VCHIQ_ERROR;
}

BUG_ON((flags & (QMFLAGS_NO_MUTEX_LOCK |
QMFLAGS_NO_MUTEX_UNLOCK)) != 0);

Expand Down Expand Up @@ -923,7 +934,6 @@ queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
header, size, VCHIQ_MSG_SRCPORT(msgid),
VCHIQ_MSG_DSTPORT(msgid));

BUG_ON(!service);
BUG_ON((flags & (QMFLAGS_NO_MUTEX_LOCK |
QMFLAGS_NO_MUTEX_UNLOCK)) != 0);

Expand Down

0 comments on commit 6b8db0b

Please sign in to comment.