Skip to content

Commit 91e7ba4

Browse files
committed
ASoC: SOF: ipc4-topology: Correct the allocation size for bytes controls
The size of the data behind of scontrol->ipc_control_data for bytes controls is: [1] sizeof(struct sof_ipc4_control_data) + // kernel only struct [2] sizeof(struct sof_abi_hdr)) + payload The max_size specifies the size of [2] and it is coming from topology. Change the function to take this into account and allocate adequate amount of memory behind scontrol->ipc_control_data. With the change we will allocate [1] amount more memory to be able to hold the full size of data. Fixes: 1bfde58 ("ASoC: SOF: ipc4-topology: add byte kcontrol support") Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 0354583 commit 91e7ba4

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

sound/soc/sof/ipc4-topology.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,22 +2875,41 @@ static int sof_ipc4_control_load_bytes(struct snd_sof_dev *sdev, struct snd_sof_
28752875
struct sof_ipc4_msg *msg;
28762876
int ret;
28772877

2878-
if (scontrol->max_size < (sizeof(*control_data) + sizeof(struct sof_abi_hdr))) {
2879-
dev_err(sdev->dev, "insufficient size for a bytes control %s: %zu.\n",
2878+
/*
2879+
* The max_size is coming from topology and indicates the maximum size
2880+
* of sof_abi_hdr plus the payload, which excludes the local only
2881+
* 'struct sof_ipc4_control_data'
2882+
*/
2883+
if (scontrol->max_size < sizeof(struct sof_abi_hdr)) {
2884+
dev_err(sdev->dev,
2885+
"insufficient maximum size for a bytes control %s: %zu.\n",
28802886
scontrol->name, scontrol->max_size);
28812887
return -EINVAL;
28822888
}
28832889

2884-
if (scontrol->priv_size > scontrol->max_size - sizeof(*control_data)) {
2885-
dev_err(sdev->dev, "scontrol %s bytes data size %zu exceeds max %zu.\n",
2886-
scontrol->name, scontrol->priv_size,
2887-
scontrol->max_size - sizeof(*control_data));
2890+
if (scontrol->priv_size > scontrol->max_size) {
2891+
dev_err(sdev->dev,
2892+
"bytes control %s initial data size %zu exceeds max %zu.\n",
2893+
scontrol->name, scontrol->priv_size, scontrol->max_size);
2894+
return -EINVAL;
2895+
}
2896+
2897+
if (scontrol->priv_size < sizeof(struct sof_abi_hdr)) {
2898+
dev_err(sdev->dev,
2899+
"bytes control %s initial data size %zu is insufficient.\n",
2900+
scontrol->name, scontrol->priv_size);
28882901
return -EINVAL;
28892902
}
28902903

2891-
scontrol->size = sizeof(struct sof_ipc4_control_data) + scontrol->priv_size;
2904+
/*
2905+
* The used size behind the cdata pointer, which can be smaller than
2906+
* the maximum size
2907+
*/
2908+
scontrol->size = sizeof(*control_data) + scontrol->priv_size;
28922909

2893-
scontrol->ipc_control_data = kzalloc(scontrol->max_size, GFP_KERNEL);
2910+
/* Allocate the cdata: local struct size + maximum payload size */
2911+
scontrol->ipc_control_data = kzalloc(sizeof(*control_data) + scontrol->max_size,
2912+
GFP_KERNEL);
28942913
if (!scontrol->ipc_control_data)
28952914
return -ENOMEM;
28962915

0 commit comments

Comments
 (0)