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. The type dispatch and the empty-payload check are re-evaluated for the restored data, so no zero-length update is sent and the message format matches the restored type. 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 | 60 +++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/sound/soc/sof/ipc4-control.c b/sound/soc/sof/ipc4-control.c index ace3bf2f719d..665afea29d28 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,13 +312,10 @@ 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); - if (ret < 0) - dev_err(scomp->dev, "%s: Failed to set control update for %s\n", - __func__, scontrol->name); kfree(msg_data); return ret; } @@ -508,11 +504,13 @@ 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; - int ret = 0; + void *old_ipc_control_data; + bool restored = false; + int ret; /* Send the new data to the firmware only if it is powered up */ if (set) { if (!pm_runtime_active(sdev->dev)) return 0; @@ -522,27 +520,47 @@ static int sof_ipc4_set_get_bytes_data(struct snd_sof_dev *sdev, scontrol->name); return 0; } } + old_ipc_control_data = scontrol->old_ipc_control_data; + +replay: if (data->type == SOF_IPC4_BYTES_CONTROL_PARAM_ID) { + if (!set) + return sof_ipc4_refresh_bytes_control(scontrol, lock); + ret = sof_ipc4_send_bytes_control_data(scontrol, lock); + } else { + memcpy(&msg, &cdata->msg, sizeof(msg)); + msg.extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(data->type); + + msg.data_ptr = data->data; if (set) - return sof_ipc4_set_bytes_control_data(scontrol, lock); + msg.data_size = data->size; else - return sof_ipc4_refresh_bytes_control(scontrol, lock); - } + msg.data_size = scontrol->max_size - sizeof(*data); - memcpy(&msg, &cdata->msg, sizeof(msg)); - msg.extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(data->type); + ret = sof_ipc4_set_get_kcontrol_data(scontrol, &msg, set, lock); + } - msg.data_ptr = data->data; - if (set) - msg.data_size = data->size; - else - msg.data_size = scontrol->max_size - sizeof(*data); + /* + * The new data was rejected and sof_ipc4_set_get_kcontrol_data() + * restored the last known good configuration. Revalidate the restored + * data and replay the message rebuilt from it, so an empty payload is + * not sent and the format matches the restored type. + */ + if (ret < 0 && set && !restored && old_ipc_control_data && + !scontrol->old_ipc_control_data) { + if (!data->size) { + dev_dbg(sdev->dev, "%s: No data to be sent.\n", + scontrol->name); + return 0; + } + restored = true; + goto replay; + } - 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