Skip to content

Commit

Permalink
ASoC: SOF: ipc3-control: Merge functions to handle bytes_ext get vari…
Browse files Browse the repository at this point in the history
…ants

The code for bytes_ext_get and bytes_ext_volatile_get is identical with
the only difference is that in case of volatile_get we refresh the data
from the DSP before returning it to user space.

Convert the callbacks to a simple wrapper for the same function.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/20230313110344.16644-3-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Peter Ujfalusi authored and Mark Brown committed Mar 13, 2023
1 parent 3eac8de commit 76fc628
Showing 1 changed file with 23 additions and 57 deletions.
80 changes: 23 additions & 57 deletions sound/soc/sof/ipc3-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,55 +343,6 @@ static int sof_ipc3_bytes_put(struct snd_sof_control *scontrol,
return 0;
}

static int sof_ipc3_bytes_ext_get(struct snd_sof_control *scontrol,
const unsigned int __user *binary_data, unsigned int size)
{
struct snd_ctl_tlv __user *tlvd = (struct snd_ctl_tlv __user *)binary_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct snd_soc_component *scomp = scontrol->scomp;
struct snd_ctl_tlv header;
size_t data_size;

sof_ipc3_refresh_control(scontrol);

/*
* Decrement the limit by ext bytes header size to
* ensure the user space buffer is not exceeded.
*/
if (size < sizeof(struct snd_ctl_tlv))
return -ENOSPC;

size -= sizeof(struct snd_ctl_tlv);

/* set the ABI header values */
cdata->data->magic = SOF_ABI_MAGIC;
cdata->data->abi = SOF_ABI_VERSION;

/* check data size doesn't exceed max coming from topology */
if (cdata->data->size > scontrol->max_size - sizeof(struct sof_abi_hdr)) {
dev_err_ratelimited(scomp->dev, "User data size %d exceeds max size %zu\n",
cdata->data->size,
scontrol->max_size - sizeof(struct sof_abi_hdr));
return -EINVAL;
}

data_size = cdata->data->size + sizeof(struct sof_abi_hdr);

/* make sure we don't exceed size provided by user space for data */
if (data_size > size)
return -ENOSPC;

header.numid = cdata->cmd;
header.length = data_size;
if (copy_to_user(tlvd, &header, sizeof(struct snd_ctl_tlv)))
return -EFAULT;

if (copy_to_user(tlvd->tlv, cdata->data, data_size))
return -EFAULT;

return 0;
}

static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol,
const unsigned int __user *binary_data,
unsigned int size)
Expand Down Expand Up @@ -457,16 +408,15 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol,
return 0;
}

static int sof_ipc3_bytes_ext_volatile_get(struct snd_sof_control *scontrol,
const unsigned int __user *binary_data,
unsigned int size)
static int _sof_ipc3_bytes_ext_get(struct snd_sof_control *scontrol,
const unsigned int __user *binary_data,
unsigned int size, bool from_dsp)
{
struct snd_ctl_tlv __user *tlvd = (struct snd_ctl_tlv __user *)binary_data;
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
struct snd_soc_component *scomp = scontrol->scomp;
struct snd_ctl_tlv header;
size_t data_size;
int ret;

/*
* Decrement the limit by ext bytes header size to
Expand All @@ -482,9 +432,12 @@ static int sof_ipc3_bytes_ext_volatile_get(struct snd_sof_control *scontrol,
cdata->data->abi = SOF_ABI_VERSION;

/* get all the component data from DSP */
ret = sof_ipc3_set_get_kcontrol_data(scontrol, false, true);
if (ret < 0)
return ret;
if (from_dsp) {
int ret = sof_ipc3_set_get_kcontrol_data(scontrol, false, true);

if (ret < 0)
return ret;
}

/* check data size doesn't exceed max coming from topology */
if (cdata->data->size > scontrol->max_size - sizeof(struct sof_abi_hdr)) {
Expand All @@ -508,7 +461,20 @@ static int sof_ipc3_bytes_ext_volatile_get(struct snd_sof_control *scontrol,
if (copy_to_user(tlvd->tlv, cdata->data, data_size))
return -EFAULT;

return ret;
return 0;
}

static int sof_ipc3_bytes_ext_get(struct snd_sof_control *scontrol,
const unsigned int __user *binary_data, unsigned int size)
{
return _sof_ipc3_bytes_ext_get(scontrol, binary_data, size, false);
}

static int sof_ipc3_bytes_ext_volatile_get(struct snd_sof_control *scontrol,
const unsigned int __user *binary_data,
unsigned int size)
{
return _sof_ipc3_bytes_ext_get(scontrol, binary_data, size, true);
}

static void snd_sof_update_control(struct snd_sof_control *scontrol,
Expand Down

0 comments on commit 76fc628

Please sign in to comment.