ASoC: SOF: Use flexible allocation for control data
Subsystems (3)
PATCH 1/1 ASoC: SOF: Use flexible allocation for control data
Allocate IPC3 and IPC4 channel control data with kzalloc_flex() for the trailing channel-value arrays instead of open-coding the struct_size() allocation.
The existing scontrol size field continues to record the payload size used by the control paths.
--- sound/soc/sof/ipc3-topology.c | 6 ++++-- sound/soc/sof/ipc4-topology.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)
sound/soc/sof/ipc3-topology.c +4 -2
@@ -1826,7 +1826,8 @@ static int sof_ipc3_control_load_volume(struct snd_sof_dev *sdev, struct snd_sof/* init the volume get/put data */ scontrol->size =struct_size (cdata, chanv, scontrol->num_channels); - scontrol->ipc_control_data =kzalloc (scontrol->size,GFP_KERNEL ); + scontrol->ipc_control_data =kzalloc_flex (*cdata, chanv, + scontrol->num_channels);if (!scontrol->ipc_control_data)return -ENOMEM ;
@@ -1857,7 +1858,8 @@ static int sof_ipc3_control_load_enum(struct snd_sof_dev *sdev, struct snd_sof_c/* init the enum get/put data */ scontrol->size =struct_size (cdata, chanv, scontrol->num_channels); - scontrol->ipc_control_data =kzalloc (scontrol->size,GFP_KERNEL ); + scontrol->ipc_control_data =kzalloc_flex (*cdata, chanv, + scontrol->num_channels);if (!scontrol->ipc_control_data)return -ENOMEM ;
sound/soc/sof/ipc4-topology.c +4 -2
@@ -2863,7 +2863,8 @@ static int sof_ipc4_control_load_volume(struct snd_sof_dev *sdev, struct snd_sof scontrol->size =struct_size (control_data, chanv, scontrol->num_channels);/* scontrol->ipc_control_data will be freed in sof_control_unload */ - scontrol->ipc_control_data =kzalloc (scontrol->size,GFP_KERNEL ); + scontrol->ipc_control_data =kzalloc_flex (*control_data, chanv, + scontrol->num_channels);if (!scontrol->ipc_control_data)return -ENOMEM ;
@@ -2905,7 +2906,8 @@ static int sof_ipc4_control_load_enum(struct snd_sof_dev *sdev, struct snd_sof_c scontrol->size =struct_size (control_data, chanv, scontrol->num_channels);/* scontrol->ipc_control_data will be freed in sof_control_unload */ - scontrol->ipc_control_data =kzalloc (scontrol->size,GFP_KERNEL ); + scontrol->ipc_control_data =kzalloc_flex (*control_data, chanv, + scontrol->num_channels);if (!scontrol->ipc_control_data)return -ENOMEM ;
Signature · 1 line
2.54.0
Péter Ujfalusi
maintainerQuoted 19 lines · Rosen Penev
Allocate IPC3 and IPC4 channel control data with
kzalloc_flex()for the trailing channel-value arrays instead of open-coding thestruct_size()allocation.The existing scontrol size field continues to record the payload size used by the control paths.
Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- sound/soc/sof/ipc3-topology.c | 6 ++++-- sound/soc/sof/ipc4-topology.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)sound/soc/sof/ipc3-topology.c +0
-0
sound/soc/sof/ipc3-topology.c static int sof_ipc3_control_load_volume(struct snd_sof_dev *sdev, struct snd_sof · line 1830
Quoted 6 lines
sound/soc/sof/ipc3-topology.c +2
-1@@ -1826,7 +1826,8 @@ static int sof_ipc3_control_load_volume(struct snd_sof_dev *sdev, struct snd_sof/* init the volume get/put data */ scontrol->size =struct_size (cdata, chanv, scontrol->num_channels); - scontrol->ipc_control_data =kzalloc (scontrol->size,GFP_KERNEL ); + scontrol->ipc_control_data =kzalloc_flex (*cdata, chanv, + scontrol->num_channels);
I don't think this helps at all.
We need to calculate the size anyways, so it is better to use that, no need to do double calculation.
Quoted 37 lines
sound/soc/sof/ipc3-topology.c +2
-1if (!scontrol->ipc_control_data)return -ENOMEM ;@@ -1857,7 +1858,8 @@ static int sof_ipc3_control_load_enum(struct snd_sof_dev *sdev, struct snd_sof_c/* init the enum get/put data */ scontrol->size =struct_size (cdata, chanv, scontrol->num_channels); - scontrol->ipc_control_data =kzalloc (scontrol->size,GFP_KERNEL ); + scontrol->ipc_control_data =kzalloc_flex (*cdata, chanv, + scontrol->num_channels);if (!scontrol->ipc_control_data)return -ENOMEM ;sound/soc/sof/ipc4-topology.c +4
-2@@ -2863,7 +2863,8 @@ static int sof_ipc4_control_load_volume(struct snd_sof_dev *sdev, struct snd_sof scontrol->size =struct_size (control_data, chanv, scontrol->num_channels);/* scontrol->ipc_control_data will be freed in sof_control_unload */ - scontrol->ipc_control_data =kzalloc (scontrol->size,GFP_KERNEL ); + scontrol->ipc_control_data =kzalloc_flex (*control_data, chanv, + scontrol->num_channels);if (!scontrol->ipc_control_data)return -ENOMEM ;@@ -2905,7 +2906,8 @@ static int sof_ipc4_control_load_enum(struct snd_sof_dev *sdev, struct snd_sof_c scontrol->size =struct_size (control_data, chanv, scontrol->num_channels);/* scontrol->ipc_control_data will be freed in sof_control_unload */ - scontrol->ipc_control_data =kzalloc (scontrol->size,GFP_KERNEL ); + scontrol->ipc_control_data =kzalloc_flex (*control_data, chanv, + scontrol->num_channels);if (!scontrol->ipc_control_data)return -ENOMEM ;
Signature · 1 line
Péter