avoid deref

We can avoid a deref when we use container_of to get from the interface
to the handle.
This commit is contained in:
Wim Taymans 2016-10-12 17:27:29 +02:00
parent 6b3bb79e70
commit 82414810e8
23 changed files with 433 additions and 385 deletions

View file

@ -116,10 +116,10 @@ spa_alsa_source_node_get_props (SpaNode *node,
{
SpaALSASource *this;
if (node == NULL || node->handle == NULL || props == NULL)
if (node == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
*props = &this->props[0].props;
@ -135,10 +135,10 @@ spa_alsa_source_node_set_props (SpaNode *node,
SpaALSAProps *p;
SpaResult res;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
p = &this->props[1];
if (props == NULL) {
@ -157,10 +157,10 @@ spa_alsa_source_node_send_command (SpaNode *node,
{
SpaALSASource *this;
if (node == NULL || node->handle == NULL || command == NULL)
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
switch (command->type) {
case SPA_NODE_COMMAND_INVALID:
@ -194,10 +194,10 @@ spa_alsa_source_node_set_event_callback (SpaNode *node,
{
SpaALSASource *this;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
this->event_cb = event;
this->user_data = user_data;
@ -212,7 +212,7 @@ spa_alsa_source_node_get_n_ports (SpaNode *node,
unsigned int *n_output_ports,
unsigned int *max_output_ports)
{
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
@ -234,7 +234,7 @@ spa_alsa_source_node_get_port_ids (SpaNode *node,
unsigned int n_output_ports,
uint32_t *output_ids)
{
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_output_ports > 0 && output_ids != NULL)
@ -271,10 +271,10 @@ spa_alsa_source_node_port_enum_formats (SpaNode *node,
SpaALSASource *this;
int index;
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
if (node == NULL || format == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -336,10 +336,10 @@ spa_alsa_source_node_port_set_format (SpaNode *node,
SpaALSASource *this;
SpaResult res;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -392,10 +392,10 @@ spa_alsa_source_node_port_get_format (SpaNode *node,
{
SpaALSASource *this;
if (node == NULL || node->handle == NULL || format == NULL)
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -416,10 +416,10 @@ spa_alsa_source_node_port_get_info (SpaNode *node,
{
SpaALSASource *this;
if (node == NULL || node->handle == NULL || info == NULL)
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -458,13 +458,13 @@ spa_alsa_source_node_port_use_buffers (SpaNode *node,
SpaResult res;
int i;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
@ -517,13 +517,13 @@ spa_alsa_source_node_port_alloc_buffers (SpaNode *node,
{
SpaALSASource *this;
if (node == NULL || node->handle == NULL || buffers == NULL)
if (node == NULL || buffers == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if (this->n_buffers == 0)
return SPA_RESULT_NO_FORMAT;
@ -539,10 +539,10 @@ spa_alsa_source_node_port_get_status (SpaNode *node,
{
SpaALSASource *this;
if (node == NULL || node->handle == NULL || status == NULL)
if (node == NULL || status == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -569,10 +569,10 @@ spa_alsa_source_node_port_pull_output (SpaNode *node,
unsigned int i;
bool have_error = false;
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
if (node == NULL || n_info == 0 || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
for (i = 0; i < n_info; i++) {
SpaALSABuffer *b;
@ -614,10 +614,10 @@ spa_alsa_source_node_port_reuse_buffer (SpaNode *node,
{
SpaALSASource *this;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) node->handle;
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
@ -643,7 +643,6 @@ spa_alsa_source_node_port_push_event (SpaNode *node,
}
static const SpaNode alsasource_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
@ -692,10 +691,10 @@ spa_alsa_source_clock_get_time (SpaClock *clock,
{
SpaALSASource *this;
if (clock == NULL || clock->handle == NULL)
if (clock == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaALSASource *) clock->handle;
this = SPA_CONTAINER_OF (clock, SpaALSASource, clock);
if (rate)
*rate = SPA_USEC_PER_SEC;
@ -708,7 +707,6 @@ spa_alsa_source_clock_get_time (SpaClock *clock,
}
static const SpaClock alsasource_clock = {
NULL,
sizeof (SpaClock),
NULL,
SPA_CLOCK_STATE_STOPPED,
@ -779,9 +777,7 @@ alsa_source_init (const SpaHandleFactory *factory,
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
this->node = alsasource_node;
this->node.handle = handle;
this->clock = alsasource_clock;
this->clock.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info;
this->stream = SND_PCM_STREAM_CAPTURE;