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

@ -186,10 +186,10 @@ spa_v4l2_source_node_get_props (SpaNode *node,
{
SpaV4l2Source *this;
if (node == NULL || node->handle == NULL || props == NULL)
if (node == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
*props = &this->props[0].props;
@ -205,10 +205,10 @@ spa_v4l2_source_node_set_props (SpaNode *node,
SpaV4l2SourceProps *p;
SpaResult res;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
p = &this->props[1];
if (props == NULL) {
@ -228,10 +228,10 @@ spa_v4l2_source_node_send_command (SpaNode *node,
SpaV4l2Source *this;
SpaResult res;
if (node == NULL || node->handle == NULL || command == NULL)
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
switch (command->type) {
case SPA_NODE_COMMAND_INVALID:
@ -288,10 +288,10 @@ spa_v4l2_source_node_set_event_callback (SpaNode *node,
{
SpaV4l2Source *this;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
this->event_cb = event;
this->user_data = user_data;
@ -306,7 +306,7 @@ spa_v4l2_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)
@ -328,7 +328,7 @@ spa_v4l2_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)
@ -382,10 +382,10 @@ spa_v4l2_source_node_port_enum_formats (SpaNode *node,
SpaV4l2Source *this;
SpaResult res;
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
if (node == NULL || format == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -408,10 +408,10 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
V4l2Format *f, *tf;
size_t fs;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -477,10 +477,10 @@ spa_v4l2_source_node_port_get_format (SpaNode *node,
SpaV4l2Source *this;
SpaV4l2State *state;
if (node == NULL || node->handle == NULL || format == NULL)
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -503,10 +503,10 @@ spa_v4l2_source_node_port_get_info (SpaNode *node,
{
SpaV4l2Source *this;
if (node == NULL || node->handle == NULL || info == NULL)
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -545,10 +545,10 @@ spa_v4l2_source_node_port_use_buffers (SpaNode *node,
SpaV4l2State *state;
SpaResult res;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -588,10 +588,10 @@ spa_v4l2_source_node_port_alloc_buffers (SpaNode *node,
SpaV4l2State *state;
SpaResult res;
if (node == NULL || node->handle == NULL || buffers == NULL)
if (node == NULL || buffers == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -621,10 +621,10 @@ spa_v4l2_source_node_port_get_status (SpaNode *node,
{
SpaV4l2Source *this;
if (node == NULL || node->handle == NULL || status == NULL)
if (node == NULL || status == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -652,10 +652,10 @@ spa_v4l2_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 = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
for (i = 0; i < n_info; i++) {
V4l2Buffer *b;
@ -699,10 +699,10 @@ spa_v4l2_source_node_port_reuse_buffer (SpaNode *node,
SpaV4l2State *state;
SpaResult res;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
@ -731,7 +731,6 @@ spa_v4l2_source_node_port_push_event (SpaNode *node,
static const SpaNode v4l2source_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
@ -781,10 +780,10 @@ spa_v4l2_source_clock_get_time (SpaClock *clock,
SpaV4l2Source *this;
SpaV4l2State *state;
if (clock == NULL || clock->handle == NULL)
if (clock == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) clock->handle;
this = SPA_CONTAINER_OF (clock, SpaV4l2Source, clock);
state = &this->state[0];
if (rate)
@ -798,7 +797,6 @@ spa_v4l2_source_clock_get_time (SpaClock *clock,
}
static const SpaClock v4l2source_clock = {
NULL,
sizeof (SpaClock),
NULL,
SPA_CLOCK_STATE_STOPPED,
@ -874,9 +872,7 @@ v4l2_source_init (const SpaHandleFactory *factory,
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
this->node = v4l2source_node;
this->node.handle = handle;
this->clock = v4l2source_clock;
this->clock.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info;
reset_v4l2_source_props (&this->props[1]);