Skip to content

Commit

Permalink
component: ignore multiple additions of the same component
Browse files Browse the repository at this point in the history
Permit masters to call component_master_add_child() and match the same
child multiple times.  This may happen if there's multiple connections
to a single component device from other devices.  In such scenarios,
we should not return a failure, but instead ignore the attempt.

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Russell King committed Jul 3, 2014
1 parent c334940 commit fcbcebc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions drivers/base/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,24 @@ static void component_detach_master(struct master *master, struct component *c)
c->master = NULL;
}

/*
* Add a component to a master, finding the component via the compare
* function and compare data. This is safe to call for duplicate matches
* and will not result in the same component being added multiple times.
*/
int component_master_add_child(struct master *master,
int (*compare)(struct device *, void *), void *compare_data)
{
struct component *c;
int ret = -ENXIO;

list_for_each_entry(c, &component_list, node) {
if (c->master)
if (c->master && c->master != master)
continue;

if (compare(c->dev, compare_data)) {
component_attach_master(master, c);
if (!c->master)
component_attach_master(master, c);
ret = 0;
break;
}
Expand Down

0 comments on commit fcbcebc

Please sign in to comment.