Skip to content

Commit 1e9c7ce

Browse files
committed
Merge series "ASoC: topology: fix error handling flow" from Pierre-Louis Bossart <[email protected]>:
While experimenting and introducing errors in Baytrail topology files until I got them right, I encountered multiple kernel oopses and memory leaks. This is a first batch to harden the code, but we should probably think of a tool to fuzz the topology... Pierre-Louis Bossart (5): ASoC: topology: fix kernel oops on route addition error ASoC: topology: fix tlvs in error handling for widget_dmixer ASoC: topology: use break on errors, not continue ASoC: topology: factor kfree(se) in error handling ASoC: topology: add more logs when topology load fails. sound/soc/soc-topology.c | 97 ++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 39 deletions(-) base-commit: a5911ac -- 2.25.1
2 parents 5f886d7 + 8edac48 commit 1e9c7ce

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

sound/soc/soc-topology.c

Lines changed: 18 additions & 6 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.
@@ -1359,14 +1371,14 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create(
13591371
if (err < 0) {
13601372
dev_err(tplg->dev, "ASoC: failed to init %s\n",
13611373
mc->hdr.name);
1362-
soc_tplg_free_tlv(tplg, &kc[i]);
13631374
goto err_sm;
13641375
}
13651376
}
13661377
return kc;
13671378

13681379
err_sm:
13691380
for (; i >= 0; i--) {
1381+
soc_tplg_free_tlv(tplg, &kc[i]);
13701382
sm = (struct soc_mixer_control *)kc[i].private_value;
13711383
kfree(sm);
13721384
kfree(kc[i].name);

0 commit comments

Comments
 (0)