Skip to content

Commit 6f0307d

Browse files
plbossartbroonie
authored andcommitted
ASoC: topology: fix kernel oops on route addition error
When errors happens while loading graph components, the kernel oopses while trying to remove all topology components. This can be root-caused to a list pointing to memory that was already freed on error. remove_route() is already called on errors and will perform the required cleanups so there's no need to free the route memory in soc_tplg_dapm_graph_elems_load() if the route was added to the list. We do however want to free the routes allocated but not added to the list. Fixes: 7df04ea ('ASoC: topology: modify dapm route loading routine and add dapm route unloading') Signed-off-by: Pierre-Louis Bossart <[email protected]> Reviewed-by: Ranjani Sridharan <[email protected]> Reviewed-by: Kai Vehmanen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 503ed52 commit 6f0307d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

sound/soc/soc-topology.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,17 +1261,29 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
12611261
list_add(&routes[i]->dobj.list, &tplg->comp->dobj_list);
12621262

12631263
ret = soc_tplg_add_route(tplg, routes[i]);
1264-
if (ret < 0)
1264+
if (ret < 0) {
1265+
/*
1266+
* this route was added to the list, it will
1267+
* be freed in remove_route() so increment the
1268+
* counter to skip it in the error handling
1269+
* below.
1270+
*/
1271+
i++;
12651272
break;
1273+
}
12661274

12671275
/* add route, but keep going if some fail */
12681276
snd_soc_dapm_add_routes(dapm, routes[i], 1);
12691277
}
12701278

1271-
/* free memory allocated for all dapm routes in case of error */
1272-
if (ret < 0)
1273-
for (i = 0; i < count ; i++)
1274-
kfree(routes[i]);
1279+
/*
1280+
* free memory allocated for all dapm routes not added to the
1281+
* list in case of error
1282+
*/
1283+
if (ret < 0) {
1284+
while (i < count)
1285+
kfree(routes[i++]);
1286+
}
12751287

12761288
/*
12771289
* free pointer to array of dapm routes as this is no longer needed.

0 commit comments

Comments
 (0)