[alsa-devel] [PATCH v2 114/146] ASoC: soc-topology: use modern dai_link style
Pierre-Louis Bossart
pierre-louis.bossart at linux.intel.com
Thu Jun 6 16:03:59 CEST 2019
>> diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
>> index 3299ebb..f485f7f 100644
>> --- a/sound/soc/soc-topology.c
>> +++ b/sound/soc/soc-topology.c
>> @@ -560,7 +560,7 @@ static void remove_link(struct snd_soc_component
>> *comp,
>> kfree(link->name);
>> kfree(link->stream_name);
>> - kfree(link->cpu_dai_name);
>> + kfree(link->cpus->dai_name);
>>
>> list_del(&dobj->list);
>> snd_soc_remove_dai_link(comp->card, link);
>> @@ -1879,12 +1879,22 @@ static int soc_tplg_fe_link_create(struct
>> soc_tplg *tplg, struct snd_soc_tplg_pcm *pcm)
>> {
>> struct snd_soc_dai_link *link;
>> + struct snd_soc_dai_link_component *dlc;
>> int ret;
>>
>> - link = kzalloc(sizeof(struct snd_soc_dai_link), GFP_KERNEL);
>> + /* link + cpu + codec */
>> + link = kzalloc(sizeof(*link) + (2 * sizeof(*dlc)),
>> GFP_KERNEL); if (link == NULL)
>> return -ENOMEM;
>>
>> + dlc = (struct snd_soc_dai_link_component *)(link + 1);
>> +
>> + link->cpus = &dlc[0];
>> + link->codecs = &dlc[1];
>
> While I understand what is going on here, I find this bit ugly.
It's not so bad and it avoid multiple tests and tags that are just as
ugly IMHO.
> Can it perhaps be changed to something like:
>
> link = kzalloc(sizeof(*link), GFP_KERNEL);
> if (link == NULL)
> return -ENOMEM;
> link->cpus = kzalloc(sizeof(*dlc), GFP_KERNEL);
> if (link->cpus == NULL) {
> ret = -ENOMEM;
> goto err;
> }
> link->codecs = kzalloc(sizeof(*dlc), GFP_KERNEL);
> if (link->cpus == NULL) {
> ret = -ENOMEM;
> goto err;
> }
>
> (...)
> err:
> kfree(link->cpus);
> kfree(link);
> return ret;
>
> While it has a bit more of boiler plate it's easier to follow.
>
> And while I look at soc_tplg_fe_link_create() it could use some
> more memory checks, but it's a topic for separate patch.
More information about the Alsa-devel
mailing list