]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: SOF: ipc4-control: Keep the payload size up to date
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Wed, 17 Dec 2025 14:39:41 +0000 (16:39 +0200)
committerMark Brown <broonie@kernel.org>
Wed, 17 Dec 2025 16:35:47 +0000 (16:35 +0000)
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: a062c8899fed ("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>
sound/soc/sof/ipc4-control.c

index 80111672c1796f7296a0eb35ef0f2ed5d04c592d..453ed1643b89c90888390e8863f449aa09b1a734 100644 (file)
@@ -426,13 +426,21 @@ static int sof_ipc4_set_get_bytes_data(struct snd_sof_dev *sdev,
        msg->extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(data->type);
 
        msg->data_ptr = data->data;
-       msg->data_size = data->size;
+       if (set)
+               msg->data_size = data->size;
+       else
+               msg->data_size = scontrol->max_size - sizeof(*data);
 
        ret = sof_ipc4_set_get_kcontrol_data(scontrol, set, lock);
-       if (ret < 0)
+       if (ret < 0) {
                dev_err(sdev->dev, "Failed to %s for %s\n",
                        set ? "set bytes update" : "get bytes",
                        scontrol->name);
+       } else if (!set) {
+               /* Update the sizes according to the received payload data */
+               data->size = msg->data_size;
+               scontrol->size = sizeof(*cdata) + sizeof(*data) + data->size;
+       }
 
        msg->data_ptr = NULL;
        msg->data_size = 0;
@@ -448,6 +456,7 @@ static int sof_ipc4_bytes_put(struct snd_sof_control *scontrol,
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
        struct sof_abi_hdr *data = cdata->data;
        size_t size;
+       int ret;
 
        if (scontrol->max_size > sizeof(ucontrol->value.bytes.data)) {
                dev_err_ratelimited(scomp->dev,
@@ -469,9 +478,12 @@ static int sof_ipc4_bytes_put(struct snd_sof_control *scontrol,
        /* copy from kcontrol */
        memcpy(data, ucontrol->value.bytes.data, size);
 
-       sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true);
+       ret = sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true);
+       if (!ret)
+               /* Update the cdata size */
+               scontrol->size = sizeof(*cdata) + size;
 
-       return 0;
+       return ret;
 }
 
 static int sof_ipc4_bytes_get(struct snd_sof_control *scontrol,
@@ -581,6 +593,9 @@ static int sof_ipc4_bytes_ext_put(struct snd_sof_control *scontrol,
                return -EFAULT;
        }
 
+       /* Update the cdata size */
+       scontrol->size = sizeof(*cdata) + header.length;
+
        return sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true);
 }