Skip to content

Commit a4fd00d

Browse files
plbossartgregkh
authored andcommitted
ASoC: topology: fix kernel oops on route addition error
commit 6f0307d upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e60e53e commit a4fd00d

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
@@ -1284,17 +1284,29 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
12841284
list_add(&routes[i]->dobj.list, &tplg->comp->dobj_list);
12851285

12861286
ret = soc_tplg_add_route(tplg, routes[i]);
1287-
if (ret < 0)
1287+
if (ret < 0) {
1288+
/*
1289+
* this route was added to the list, it will
1290+
* be freed in remove_route() so increment the
1291+
* counter to skip it in the error handling
1292+
* below.
1293+
*/
1294+
i++;
12881295
break;
1296+
}
12891297

12901298
/* add route, but keep going if some fail */
12911299
snd_soc_dapm_add_routes(dapm, routes[i], 1);
12921300
}
12931301

1294-
/* free memory allocated for all dapm routes in case of error */
1295-
if (ret < 0)
1296-
for (i = 0; i < count ; i++)
1297-
kfree(routes[i]);
1302+
/*
1303+
* free memory allocated for all dapm routes not added to the
1304+
* list in case of error
1305+
*/
1306+
if (ret < 0) {
1307+
while (i < count)
1308+
kfree(routes[i++]);
1309+
}
12981310

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

0 commit comments

Comments
 (0)