Skip to content

Commit 46f61a0

Browse files
ujfalusiplbossart
authored andcommitted
ASoC: SOF: ipc3-topology: Move and correct size checks in sof_ipc3_control_load_bytes()
Move the size checks prior to allocating memory as these checks do not need the data to be allocated and in case of an error we would not need to free the allocation. The max size must not be less than the size of struct sof_ipc_ctrl_data + struct sof_abi_hdr as the ABI header needs to be present under all circumstances. The check was incorrectly used or between the two size checks. Fixes: b5cee8f ("ASoC: SOF: topology: Make control parsing IPC agnostic") Signed-off-by: Peter Ujfalusi <[email protected]>
1 parent 0b48f05 commit 46f61a0

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

‎sound/soc/sof/ipc3-topology.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,24 +1593,23 @@ static int sof_ipc3_control_load_bytes(struct snd_sof_dev *sdev, struct snd_sof_
15931593
struct sof_ipc_ctrl_data *cdata;
15941594
int ret;
15951595

1596-
scontrol->ipc_control_data = kzalloc(scontrol->max_size, GFP_KERNEL);
1597-
if (!scontrol->ipc_control_data)
1598-
return -ENOMEM;
1599-
1600-
if (scontrol->max_size < sizeof(*cdata) ||
1601-
scontrol->max_size < sizeof(struct sof_abi_hdr)) {
1602-
ret = -EINVAL;
1603-
goto err;
1596+
if (scontrol->max_size < (sizeof(*cdata) + sizeof(struct sof_abi_hdr))) {
1597+
dev_err(sdev->dev, "%s: insufficient size for a bytes control: %zu.\n",
1598+
__func__, scontrol->max_size);
1599+
return -EINVAL;
16041600
}
16051601

1606-
/* init the get/put bytes data */
16071602
if (scontrol->priv_size > scontrol->max_size - sizeof(*cdata)) {
1608-
dev_err(sdev->dev, "err: bytes data size %zu exceeds max %zu.\n",
1603+
dev_err(sdev->dev,
1604+
"%s: bytes data size %zu exceeds max %zu.\n", __func__,
16091605
scontrol->priv_size, scontrol->max_size - sizeof(*cdata));
1610-
ret = -EINVAL;
1611-
goto err;
1606+
return -EINVAL;
16121607
}
16131608

1609+
scontrol->ipc_control_data = kzalloc(scontrol->max_size, GFP_KERNEL);
1610+
if (!scontrol->ipc_control_data)
1611+
return -ENOMEM;
1612+
16141613
scontrol->size = sizeof(struct sof_ipc_ctrl_data) + scontrol->priv_size;
16151614

16161615
cdata = scontrol->ipc_control_data;

0 commit comments

Comments
 (0)