sound/soc/sof/ipc3-topology.c | 6 ++++-- sound/soc/sof/ipc4-topology.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)
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.
Assisted-by: Codex:GPT-5.5
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
sound/soc/sof/ipc3-topology.c | 6 ++++--
sound/soc/sof/ipc4-topology.c | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c
index 8c37c0657315..9597f619fbe4 100644
--- a/sound/soc/sof/ipc3-topology.c
+++ b/sound/soc/sof/ipc3-topology.c
@@ -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;
diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c
index 76812d8fb567..9fd04a7857f6 100644
--- a/sound/soc/sof/ipc4-topology.c
+++ b/sound/soc/sof/ipc4-topology.c
@@ -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;
--
2.54.0
On 19/05/2026 03:47, Rosen Penev wrote: > 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. > > Assisted-by: Codex:GPT-5.5 > Signed-off-by: Rosen Penev <rosenp@gmail.com> > --- > sound/soc/sof/ipc3-topology.c | 6 ++++-- > sound/soc/sof/ipc4-topology.c | 6 ++++-- > 2 files changed, 8 insertions(+), 4 deletions(-) > > diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c > index 8c37c0657315..9597f619fbe4 100644 > --- a/sound/soc/sof/ipc3-topology.c > +++ b/sound/soc/sof/ipc3-topology.c > @@ -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. > 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; > > diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c > index 76812d8fb567..9fd04a7857f6 100644 > --- a/sound/soc/sof/ipc4-topology.c > +++ b/sound/soc/sof/ipc4-topology.c > @@ -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; > -- Péter
© 2016 - 2026 Red Hat, Inc.