diff mbox series

Asoc: core: fix wrong size kzalloc for rtd's components member

Message ID tencent_59850BB028662B6F2D49D7F3624AB84CCF05@qq.com
State Accepted
Commit 66a796c04b639e2658b4d820dd5fbc842c8c3aae
Headers show
Series Asoc: core: fix wrong size kzalloc for rtd's components member | expand

Commit Message

lishqchn Nov. 8, 2022, 4:24 a.m. UTC
The actual space for struct snd_soc_component has been allocated by
snd_soc_register_component, here rtd's components are pointers to
components, I replace the base size from *component to component.

Signed-off-by: lishqchn <lishqchn@qq.com>
---
 sound/soc/soc-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

lishqchn Nov. 15, 2022, 11:15 a.m. UTC | #1
rtd's flexible arrays are typeof struct snd_soc_component *components[]&nbsp; which means struct_pointer flexible arrays
sizeof(component) will allocate sizeof(struct snd_soc_component), but here only need sizeof(struct snd_soc_component *) 








------------------&nbsp;原始邮件&nbsp;------------------
发件人:                                                                                                                        "Amadeusz Sławiński"                                                                                    <amadeuszx.slawinski@linux.intel.com&gt;;
发送时间:&nbsp;2022年11月10日(星期四) 晚上7:02
收件人:&nbsp;"lishqchn"<lishqchn@qq.com&gt;;"perex"<perex@perex.cz&gt;;"tiwai"<tiwai@suse.com&gt;;
抄送:&nbsp;"alsa-devel"<alsa-devel@alsa-project.org&gt;;"broonie"<broonie@kernel.org&gt;;"lgirdwood"<lgirdwood@gmail.com&gt;;"linux-kernel"<linux-kernel@vger.kernel.org&gt;;
主题:&nbsp;Re: [PATCH] Asoc: core: fix wrong size kzalloc for rtd's components member



On 11/8/2022 5:24 AM, lishqchn wrote:
&gt; The actual space for struct snd_soc_component has been allocated by
&gt; snd_soc_register_component, here rtd's components are pointers to
&gt; components, I replace the base size from *component to component.
&gt; 
&gt; Signed-off-by: lishqchn <lishqchn@qq.com&gt;
&gt; ---
&gt;&nbsp;&nbsp; sound/soc/soc-core.c | 2 +-
&gt;&nbsp;&nbsp; 1 file changed, 1 insertion(+), 1 deletion(-)
&gt; 
&gt; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
&gt; index a6d6d10cd471..d21e0284b2aa 100644
&gt; --- a/sound/soc/soc-core.c
&gt; +++ b/sound/soc/soc-core.c
&gt; @@ -459,7 +459,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
&gt;&nbsp;&nbsp; 	 */
&gt;&nbsp;&nbsp; 	rtd = devm_kzalloc(dev,
&gt;&nbsp;&nbsp; 			&nbsp;&nbsp; sizeof(*rtd) +
&gt; -			&nbsp;&nbsp; sizeof(*component) * (dai_link-&gt;num_cpus +
&gt; +			&nbsp;&nbsp; sizeof(component) * (dai_link-&gt;num_cpus +
&gt;&nbsp;&nbsp; 						 dai_link-&gt;num_codecs +
&gt;&nbsp;&nbsp; 						 dai_link-&gt;num_platforms),
&gt;&nbsp;&nbsp; 			&nbsp;&nbsp; GFP_KERNEL);

Can't struct_size macro be used instead, it is meant to be used when 
calculating size of structs containing flexible arrays at the end?
Mark Brown Nov. 15, 2022, 4:42 p.m. UTC | #2
On Tue, 8 Nov 2022 12:24:56 +0800, lishqchn wrote:
> The actual space for struct snd_soc_component has been allocated by
> snd_soc_register_component, here rtd's components are pointers to
> components, I replace the base size from *component to component.
> 
> 

Applied to

   broonie/sound.git for-next

Thanks!

[1/1] Asoc: core: fix wrong size kzalloc for rtd's components member
      commit: 66a796c04b639e2658b4d820dd5fbc842c8c3aae

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
diff mbox series

Patch

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index a6d6d10cd471..d21e0284b2aa 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -459,7 +459,7 @@  static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	 */
 	rtd = devm_kzalloc(dev,
 			   sizeof(*rtd) +
-			   sizeof(*component) * (dai_link->num_cpus +
+			   sizeof(component) * (dai_link->num_cpus +
 						 dai_link->num_codecs +
 						 dai_link->num_platforms),
 			   GFP_KERNEL);