ASoC: SOF: topology: Use struct_size() helper
Subsystems (3)
PATCH 1/1 ASoC: SOF: topology: Use struct_size() helper
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.
So, replace the following form:
sizeof(struct sof_ipc_ctrl_data) + sizeof(struct sof_ipc_ctrl_value_chan) *
le32_to_cpu(mc->num_channels)
with:
struct_size(scontrol->control_data, chanv, le32_to_cpu(mc->num_channels))
and so on...
This code was detected with the help of Coccinelle.
--- sound/soc/sof/topology.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
sound/soc/sof/topology.c +4 -6
@@ -442,9 +442,8 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,return -EINVAL ;/* init the volume get/put data */ - scontrol->size =sizeof (struct sof_ipc_ctrl_data ) + -sizeof (struct sof_ipc_ctrl_value_chan ) * -le32_to_cpu (mc->num_channels); + scontrol->size =struct_size (scontrol->control_data, chanv, +le32_to_cpu (mc->num_channels)); scontrol->control_data =kzalloc (scontrol->size,GFP_KERNEL );if (!scontrol->control_data)return -ENOMEM ;
@@ -501,9 +500,8 @@ static int sof_control_load_enum(struct snd_soc_component *scomp,return -EINVAL ;/* init the enum get/put data */ - scontrol->size =sizeof (struct sof_ipc_ctrl_data ) + -sizeof (struct sof_ipc_ctrl_value_chan ) * -le32_to_cpu (ec->num_channels); + scontrol->size =struct_size (scontrol->control_data, chanv, +le32_to_cpu (ec->num_channels)); scontrol->control_data =kzalloc (scontrol->size,GFP_KERNEL );if (!scontrol->control_data)return -ENOMEM ;
Signature · 1 line
2.21.0
Mark Brown
maintainerApplied "ASoC: SOF: topology: Use struct_size() helper" to the asoc tree
The patch
ASoC: SOF: topology: Use struct_size() helper
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.3
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
Quoted 1 line
From
41f4fadb34af8cdcd7c1e7b4118b8db14d06849eMon Sep 17 00:00:00 2001
From: "Gustavo A. R. Silva" <[email protected]>
Date: Fri, 24 May 2019 11:10:51 -0500
Subject: [PATCH] ASoC: SOF: topology: Use struct_size() helper
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.
So, replace the following form:
sizeof(struct sof_ipc_ctrl_data) + sizeof(struct sof_ipc_ctrl_value_chan) *
le32_to_cpu(mc->num_channels)
with:
struct_size(scontrol->control_data, chanv, le32_to_cpu(mc->num_channels))
and so on...
This code was detected with the help of Coccinelle.
--- sound/soc/sof/topology.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
sound/soc/sof/topology.c +4 -6
@@ -442,9 +442,8 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,return -EINVAL ;/* init the volume get/put data */ - scontrol->size =sizeof (struct sof_ipc_ctrl_data ) + -sizeof (struct sof_ipc_ctrl_value_chan ) * -le32_to_cpu (mc->num_channels); + scontrol->size =struct_size (scontrol->control_data, chanv, +le32_to_cpu (mc->num_channels)); scontrol->control_data =kzalloc (scontrol->size,GFP_KERNEL );if (!scontrol->control_data)return -ENOMEM ;
@@ -501,9 +500,8 @@ static int sof_control_load_enum(struct snd_soc_component *scomp,return -EINVAL ;/* init the enum get/put data */ - scontrol->size =sizeof (struct sof_ipc_ctrl_data ) + -sizeof (struct sof_ipc_ctrl_value_chan ) * -le32_to_cpu (ec->num_channels); + scontrol->size =struct_size (scontrol->control_data, chanv, +le32_to_cpu (ec->num_channels)); scontrol->control_data =kzalloc (scontrol->size,GFP_KERNEL );if (!scontrol->control_data)return -ENOMEM ;
Signature · 1 line
2.20.1