Skip to content

Commit

Permalink
mmal 64bit: Fix client context handling for events
Browse files Browse the repository at this point in the history
  • Loading branch information
6by9 committed Nov 11, 2019
1 parent 23d2117 commit b0dc008
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions interface/mmal/vc/mmal_vc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ static MMAL_STATUS_T mmal_vc_port_connect(MMAL_PORT_T *port, MMAL_PORT_T *other_
static void mmal_vc_do_callback(MMAL_COMPONENT_T *component)
{
MMAL_COMPONENT_MODULE_T *module = component->priv->module;
MMAL_VC_CLIENT_BUFFER_CONTEXT_T *client_context;
MMAL_BUFFER_HEADER_T *buffer;
MMAL_PORT_T *port;

Expand All @@ -507,8 +506,8 @@ static void mmal_vc_do_callback(MMAL_COMPONENT_T *component)
mmal_event_error_send(port->component, MMAL_EIO);

/* Events generated by this component are handled differently */
client_context = mmal_vc_lookup_client_context(mmal_buffer_header_driver_data(buffer)->client_context);
if (client_context == &component->priv->module->event_ctx)
if (mmal_buffer_header_driver_data(buffer)->client_context ==
component->priv->module->event_ctx_handle)
{
mmal_port_event_send(port, buffer);
return;
Expand Down Expand Up @@ -541,6 +540,7 @@ static void mmal_vc_port_send_callback(mmal_worker_buffer_from_host *msg)

buffer = client_context->buffer;
port = client_context->port;

vcos_blockpool_free(client_context);
mmal_vc_release_client_context(client_context);

Expand Down
18 changes: 13 additions & 5 deletions interface/mmal/vc/mmal_vc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ typedef struct
} MMAL_CLIENT_CONTEXT_POOL_T;

static MMAL_CLIENT_CONTEXT_POOL_T client_context_pool;
#define CLIENT_CONTEXT_MAGIC 0xFEDC0000
#define CLIENT_CONTEXT_MAGIC_MASK(a) (a & 0xFFFF)
#define CLIENT_CONTEXT_MAGIC_CHECK(a) (a & 0xFFFF0000)

uint32_t mmal_vc_allocate_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context)
{
Expand All @@ -208,15 +211,16 @@ uint32_t mmal_vc_allocate_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *contex
}
vcos_mutex_unlock(&client_context_pool.lock);

return i;
return i | CLIENT_CONTEXT_MAGIC;
}

MMAL_VC_CLIENT_BUFFER_CONTEXT_T *mmal_vc_lookup_client_context(int index)
{
if (vcos_verify(index < MAX_CLIENT_CONTEXTS))
if (vcos_verify((CLIENT_CONTEXT_MAGIC_CHECK(index) == CLIENT_CONTEXT_MAGIC) &&
(CLIENT_CONTEXT_MAGIC_MASK(index) < MAX_CLIENT_CONTEXTS)))
{
vcos_assert(client_context_pool.contexts[index].inuse);
return client_context_pool.contexts[index].ctx;
vcos_assert(client_context_pool.contexts[CLIENT_CONTEXT_MAGIC_MASK(index)].inuse);
return client_context_pool.contexts[CLIENT_CONTEXT_MAGIC_MASK(index)].ctx;
}

return NULL;
Expand All @@ -233,8 +237,12 @@ void mmal_vc_release_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context)
{
client_context_pool.contexts[i].ctx = NULL;
client_context_pool.contexts[i].inuse = 0;
break;
}
}
if (i >= MAX_CLIENT_CONTEXTS)
LOG_ERROR("Failed to release context %p - not found", context);

vcos_mutex_unlock(&client_context_pool.lock);
}

Expand Down Expand Up @@ -521,7 +529,7 @@ static VCHIQ_STATUS_T mmal_vc_vchiq_callback(VCHIQ_REASON_T reason,
LOG_TRACE("buffer to host");
mmal_worker_buffer_from_host *msg = (mmal_worker_buffer_from_host *)vchiq_header->data;
client_context = mmal_vc_lookup_client_context(msg->drvbuf.client_context);
LOG_TRACE("len %d context %p", msg->buffer_header.length, client_context);
LOG_TRACE("len %d context %p (%08x)", msg->buffer_header.length, client_context, msg->drvbuf.client_context);
vcos_assert(client_context);
vcos_assert(client_context->magic == MMAL_MAGIC);

Expand Down

0 comments on commit b0dc008

Please sign in to comment.