Linux内核audio子系统soc_new_pcm_runtime()函数里的一个bug:
在分析qcom8550 Android-T kernel-5.15的audio子系统的代码时发现一个bug:
struct snd_soc_pcm_runtime {
struct device *dev;
...
struct snd_soc_component *components[]; /* CPU/Codec/Platform */
};
static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
{
struct snd_soc_pcm_runtime *rtd;
struct snd_soc_component *component;
// 在分配rtd的内存空间时,sizeof(*component)是个bug,会导致多分配了一些内存空间,应该是sizeof(component),
// 因为,snd_soc_pcm_runtime结构体里面,struct snd_soc_component *components[];
// components是一个数组,数组里面保存的是指向snd_soc_component类型的指针。
rtd = devm_kzalloc(dev,
sizeof(*rtd) +
sizeof(*component) * (dai_link->num_cpus +
dai_link->num_codecs +
dai_link->num_platforms),
GFP_KERNEL);
}