aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2014-04-18 15:16:22 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2014-07-03 06:32:40 -0400
commitfcbcebce7159c928692dc6a5e88869f6e44438b9 (patch)
treeabc91266771d81fe0401da0febbaeba59dd425f8 /drivers/base
parentc334940ea26cb58f5514dcbb225a3f397b2684ad (diff)
component: ignore multiple additions of the same component
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>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/component.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/base/component.c b/drivers/base/component.c
index d0ebd4431736..55813e91bf0d 100644
--- a/drivers/base/component.c
+++ b/drivers/base/component.c
@@ -69,6 +69,11 @@ static void component_detach_master(struct master *master, struct component *c)
69 c->master = NULL; 69 c->master = NULL;
70} 70}
71 71
72/*
73 * Add a component to a master, finding the component via the compare
74 * function and compare data. This is safe to call for duplicate matches
75 * and will not result in the same component being added multiple times.
76 */
72int component_master_add_child(struct master *master, 77int component_master_add_child(struct master *master,
73 int (*compare)(struct device *, void *), void *compare_data) 78 int (*compare)(struct device *, void *), void *compare_data)
74{ 79{
@@ -76,11 +81,12 @@ int component_master_add_child(struct master *master,
76 int ret = -ENXIO; 81 int ret = -ENXIO;
77 82
78 list_for_each_entry(c, &component_list, node) { 83 list_for_each_entry(c, &component_list, node) {
79 if (c->master) 84 if (c->master && c->master != master)
80 continue; 85 continue;
81 86
82 if (compare(c->dev, compare_data)) { 87 if (compare(c->dev, compare_data)) {
83 component_attach_master(master, c); 88 if (!c->master)
89 component_attach_master(master, c);
84 ret = 0; 90 ret = 0;
85 break; 91 break;
86 } 92 }