From: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
To: Rosen Penev <rosenp@gmail.com>, linux-sound@vger.kernel.org
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Bard Liao <yung-chuan.liao@linux.intel.com>,
Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
Daniel Baluta <daniel.baluta@nxp.com>,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
"moderated list:SOUND - SOUND OPEN FIRMWARE (SOF) DRIVERS"
<sound-open-firmware@alsa-project.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ASoC: SOF: Use flexible allocation for control data
Date: Tue, 19 May 2026 15:04:38 +0300 [thread overview]
Message-ID: <fbd56200-c854-4e6f-a6aa-d5ab7585403a@linux.intel.com> (raw)
In-Reply-To: <20260519004749.627581-1-rosenp@gmail.com>
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
prev parent reply other threads:[~2026-05-19 12:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 0:47 Rosen Penev
2026-05-19 12:04 ` Péter Ujfalusi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fbd56200-c854-4e6f-a6aa-d5ab7585403a@linux.intel.com \
--to=peter.ujfalusi@linux.intel.com \
--cc=broonie@kernel.org \
--cc=daniel.baluta@nxp.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=pierre-louis.bossart@linux.dev \
--cc=ranjani.sridharan@linux.intel.com \
--cc=rosenp@gmail.com \
--cc=sound-open-firmware@alsa-project.org \
--cc=tiwai@suse.com \
--cc=yung-chuan.liao@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®