Skip to content
/ linux Public

Commit d6f5aed

Browse files
ujfalusiSasha Levin
authored andcommitted
ASoC: SOF: ipc4-control: Keep the payload size up to date
[ Upstream commit ebcfdbe ] When the bytes data is read from the firmware, the size of the payload can be different than what it was previously. For example when the topology did not contained payload data at all for the control, the data size was 0. For get operation allow maximum size of payload to be read and then update the sizes according to the completed message. Similarly, keep the size in sync when updating the data in firmware. With the change we will be able to read data from firmware for bytes controls which did not had initial payload defined in topology. Fixes: a062c88 ("ASoC: SOF: ipc4-control: Add support for bytes control get and put") Cc: stable@vger.kernel.org Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com> Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Link: https://patch.msgid.link/20251217143945.2667-5-peter.ujfalusi@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e1dd709 commit d6f5aed

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

sound/soc/sof/ipc4-control.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,21 @@ static int sof_ipc4_set_get_bytes_data(struct snd_sof_dev *sdev,
378378
msg->extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(data->type);
379379

380380
msg->data_ptr = data->data;
381-
msg->data_size = data->size;
381+
if (set)
382+
msg->data_size = data->size;
383+
else
384+
msg->data_size = scontrol->max_size - sizeof(*data);
382385

383386
ret = sof_ipc4_set_get_kcontrol_data(scontrol, set, lock);
384-
if (ret < 0)
387+
if (ret < 0) {
385388
dev_err(sdev->dev, "Failed to %s for %s\n",
386389
set ? "set bytes update" : "get bytes",
387390
scontrol->name);
391+
} else if (!set) {
392+
/* Update the sizes according to the received payload data */
393+
data->size = msg->data_size;
394+
scontrol->size = sizeof(*cdata) + sizeof(*data) + data->size;
395+
}
388396

389397
msg->data_ptr = NULL;
390398
msg->data_size = 0;
@@ -400,6 +408,7 @@ static int sof_ipc4_bytes_put(struct snd_sof_control *scontrol,
400408
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
401409
struct sof_abi_hdr *data = cdata->data;
402410
size_t size;
411+
int ret;
403412

404413
if (scontrol->max_size > sizeof(ucontrol->value.bytes.data)) {
405414
dev_err_ratelimited(scomp->dev,
@@ -421,9 +430,12 @@ static int sof_ipc4_bytes_put(struct snd_sof_control *scontrol,
421430
/* copy from kcontrol */
422431
memcpy(data, ucontrol->value.bytes.data, size);
423432

424-
sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true);
433+
ret = sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true);
434+
if (!ret)
435+
/* Update the cdata size */
436+
scontrol->size = sizeof(*cdata) + size;
425437

426-
return 0;
438+
return ret;
427439
}
428440

429441
static int sof_ipc4_bytes_get(struct snd_sof_control *scontrol,
@@ -533,6 +545,9 @@ static int sof_ipc4_bytes_ext_put(struct snd_sof_control *scontrol,
533545
return -EFAULT;
534546
}
535547

548+
/* Update the cdata size */
549+
scontrol->size = sizeof(*cdata) + header.length;
550+
536551
return sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true);
537552
}
538553

0 commit comments

Comments
 (0)