When a set-data request is rejected, sof_ipc4_set_get_kcontrol_data() restores the last known good data but replays the message built from the rejected data. For regular bytes controls the extension may come from the rejected data; for SOF_IPC4_BYTES_CONTROL_PARAM_ID controls the payload lives in a separate buffer that still holds the rejected data. The firmware therefore does not receive the restored configuration. Let the caller rebuild the message from the restored data and replay it. Move the param-id message setup into a helper so the payload can be reallocated with the restored size. Fixes: db38d86d0c54 ("ASoC: sof: Improve sof_ipc4_bytes_ext_put function") Cc: stable@vger.kernel.org Signed-off-by: Ye Weihua --- sound/soc/sof/ipc4-control.c | 53 ++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/sound/soc/sof/ipc4-control.c b/sound/soc/sof/ipc4-control.c index ace3bf2f719d..8ed006efe17f 100644 --- a/sound/soc/sof/ipc4-control.c +++ b/sound/soc/sof/ipc4-control.c @@ -73,14 +73,14 @@ static int sof_ipc4_set_get_kcontrol_data(struct snd_sof_control *scontrol, /* Keep the size consistent with the restored control data */ scontrol->size = sizeof(*cdata) + sizeof(*cdata->data) + cdata->data->size; kfree(scontrol->old_ipc_control_data); scontrol->old_ipc_control_data = NULL; - /* Send the last known good configuration to firmware */ - ret = iops->set_get_data(sdev, msg, msg->data_size, set); - if (ret < 0) - goto unlock; + /* + * The caller is responsible for rebuilding the message from + * the restored control data and replaying it. + */ } unlock: if (lock) mutex_unlock(&swidget->setup_mutex); @@ -287,14 +287,13 @@ static void sof_ipc4_refresh_generic_control(struct snd_sof_control *scontrol) kfree(data); } static int -sof_ipc4_set_bytes_control_data(struct snd_sof_control *scontrol, bool lock) +sof_ipc4_send_bytes_control_data(struct snd_sof_control *scontrol, bool lock) { struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data; - struct snd_soc_component *scomp = scontrol->scomp; struct sof_ipc4_control_msg_payload *msg_data; struct sof_abi_hdr *data = cdata->data; struct sof_ipc4_msg msg; size_t data_size; int ret; @@ -313,16 +312,39 @@ sof_ipc4_set_bytes_control_data(struct snd_sof_control *scontrol, bool lock) msg.data_ptr = msg_data; msg.data_size = data_size; ret = sof_ipc4_set_get_kcontrol_data(scontrol, &msg, true, lock); + + kfree(msg_data); + + return ret; +} + +static int +sof_ipc4_set_bytes_control_data(struct snd_sof_control *scontrol, bool lock) +{ + struct snd_soc_component *scomp = scontrol->scomp; + void *old_ipc_control_data; + int ret; + + old_ipc_control_data = scontrol->old_ipc_control_data; + ret = sof_ipc4_send_bytes_control_data(scontrol, lock); + if (ret < 0 && old_ipc_control_data && + !scontrol->old_ipc_control_data) { + /* + * The new data was rejected and the last known good + * configuration was restored. Rebuild the message from the + * restored control data and replay it. + */ + ret = sof_ipc4_send_bytes_control_data(scontrol, lock); + } + if (ret < 0) dev_err(scomp->dev, "%s: Failed to set control update for %s\n", __func__, scontrol->name); - kfree(msg_data); - return ret; } static int sof_ipc4_refresh_bytes_control(struct snd_sof_control *scontrol, bool lock) @@ -508,10 +530,11 @@ static int sof_ipc4_set_get_bytes_data(struct snd_sof_dev *sdev, bool set, bool lock) { struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data; struct sof_abi_hdr *data = cdata->data; struct sof_ipc4_msg msg; + void *old_ipc_control_data; int ret = 0; /* Send the new data to the firmware only if it is powered up */ if (set) { if (!pm_runtime_active(sdev->dev)) @@ -538,11 +561,25 @@ static int sof_ipc4_set_get_bytes_data(struct snd_sof_dev *sdev, if (set) msg.data_size = data->size; else msg.data_size = scontrol->max_size - sizeof(*data); + old_ipc_control_data = scontrol->old_ipc_control_data; ret = sof_ipc4_set_get_kcontrol_data(scontrol, &msg, set, lock); + if (ret < 0 && set && old_ipc_control_data && + !scontrol->old_ipc_control_data) { + /* + * The new data was rejected and the last known good + * configuration was restored. Rebuild the message from the + * restored control data and replay it. + */ + msg.extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(data->type); + msg.data_ptr = data->data; + msg.data_size = data->size; + ret = sof_ipc4_set_get_kcontrol_data(scontrol, &msg, set, lock); + } + if (ret < 0) { dev_err(sdev->dev, "Failed to %s for %s\n", set ? "set bytes update" : "get bytes", scontrol->name); } else if (!set) { -- 2.34.1