mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ASoC: SOF: Use flexible allocation for control data
@ 2026-05-19  0:47 Rosen Penev
  2026-05-19 12:04 ` Péter Ujfalusi
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-05-19  0:47 UTC (permalink / raw)
  To: linux-sound
  Cc: Liam Girdwood, Peter Ujfalusi, Bard Liao, Ranjani Sridharan,
	Daniel Baluta, Kai Vehmanen, Pierre-Louis Bossart, Mark Brown,
	Jaroslav Kysela, Takashi Iwai,
	moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS,
	open list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-19 12:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-19  0:47 [PATCH] ASoC: SOF: Use flexible allocation for control data Rosen Penev
2026-05-19 12:04 ` Péter Ujfalusi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®