Skip to content

Commit

Permalink
ASoC: SOF: control: correct the copy size for bytes kcontrol put
Browse files Browse the repository at this point in the history
BugLink: https://bugs.launchpad.net/bugs/1826181

The size for the bytes kcontrol should include the abi header, that is,
data->size + sizeof(*data), it is also aligned with get method after
this change.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
(cherry picked from commit 6f22f5976284eb1d4b27bed1521159a9faa38ae6
git://github.com/thesofproject/linux.git)
Signed-off-by: Hui Wang <hui.wang@canonical.com>
Signed-off-by: Timo Aaltonen <timo.aaltonen@canonical.com>
  • Loading branch information
keyonjie authored and tjaalton committed Jun 18, 2019
1 parent 9a66f0d commit 747b507
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sound/soc/sof/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
struct snd_sof_dev *sdev = scontrol->sdev;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_abi_hdr *data = cdata->data;
size_t size = data->size + sizeof(*data);
int ret, err;

if (be->max > sizeof(ucontrol->value.bytes.data)) {
Expand All @@ -358,10 +359,10 @@ int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
return -EINVAL;
}

if (data->size > be->max) {
if (size > be->max) {
dev_err_ratelimited(sdev->dev,
"error: size too big %d bytes max is %d\n",
data->size, be->max);
"error: size too big %zu bytes max is %d\n",
size, be->max);
return -EINVAL;
}

Expand All @@ -375,7 +376,7 @@ int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
}

/* copy from kcontrol */
memcpy(data, ucontrol->value.bytes.data, data->size);
memcpy(data, ucontrol->value.bytes.data, size);

/* notify DSP of byte control updates */
snd_sof_ipc_set_get_comp_data(sdev->ipc, scontrol,
Expand Down

0 comments on commit 747b507

Please sign in to comment.