Skip to content

Commit c334940

Browse files
author
Russell King
committed
component: fix missed cleanup in case of devres failure
In try_to_bring_up_master(), we tear down the master's component list for each error case, except for devres group failure. Fix this oversight by making the code less prone to such mistakes. Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 4c83445 commit c334940

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

‎drivers/base/component.c‎

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -113,44 +113,44 @@ static void master_remove_components(struct master *master)
113113
static int try_to_bring_up_master(struct master *master,
114114
struct component *component)
115115
{
116-
int ret = 0;
116+
int ret;
117117

118-
if (!master->bound) {
119-
/*
120-
* Search the list of components, looking for components that
121-
* belong to this master, and attach them to the master.
122-
*/
123-
if (master->ops->add_components(master->dev, master)) {
124-
/* Failed to find all components */
125-
master_remove_components(master);
126-
ret = 0;
127-
goto out;
128-
}
118+
if (master->bound)
119+
return 0;
129120

130-
if (component && component->master != master) {
131-
master_remove_components(master);
132-
ret = 0;
133-
goto out;
134-
}
121+
/*
122+
* Search the list of components, looking for components that
123+
* belong to this master, and attach them to the master.
124+
*/
125+
if (master->ops->add_components(master->dev, master)) {
126+
/* Failed to find all components */
127+
ret = 0;
128+
goto out;
129+
}
135130

136-
if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) {
137-
ret = -ENOMEM;
138-
goto out;
139-
}
131+
if (component && component->master != master) {
132+
ret = 0;
133+
goto out;
134+
}
140135

141-
/* Found all components */
142-
ret = master->ops->bind(master->dev);
143-
if (ret < 0) {
144-
devres_release_group(master->dev, NULL);
145-
dev_info(master->dev, "master bind failed: %d\n", ret);
146-
master_remove_components(master);
147-
goto out;
148-
}
136+
if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) {
137+
ret = -ENOMEM;
138+
goto out;
139+
}
149140

150-
master->bound = true;
151-
ret = 1;
141+
/* Found all components */
142+
ret = master->ops->bind(master->dev);
143+
if (ret < 0) {
144+
devres_release_group(master->dev, NULL);
145+
dev_info(master->dev, "master bind failed: %d\n", ret);
146+
goto out;
152147
}
148+
149+
master->bound = true;
150+
return 1;
151+
153152
out:
153+
master_remove_components(master);
154154

155155
return ret;
156156
}

0 commit comments

Comments
 (0)