ASoC: SOF: topology: fix get control data return type and arguments
Subsystems (3)
PATCH 1/1 ASoC: SOF: topology: fix get control data return type and arguments
From: Jaska Uimonen <[email protected]>
sof_get_control_data returns negative values even though the return value is defined unsigned (size_t). So change the return value type to int.
Add the data size as pointer argument to sof_get_control_data to avoid ambiquity in the meaning of the return type. Also make the sof_get_control_data to return -EINVAL if data pointer is valid but the size is for some reason zero.
Reported by: Dan Carpenter <[email protected]>
--- sound/soc/sof/topology.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
sound/soc/sof/topology.c +13 -10
@@ -1752,15 +1752,15 @@ static int sof_widget_load_siggen(struct snd_soc_component *scomp, int index,return ret; } -static size_t sof_get_control_data (struct snd_sof_dev *sdev, -struct snd_soc_dapm_widget *widget, -struct sof_widget_data *wdata) +static int sof_get_control_data (struct snd_sof_dev *sdev, +struct snd_soc_dapm_widget *widget, +struct sof_widget_data *wdata, +size_t *size) {const struct snd_kcontrol_new *kc;struct soc_mixer_control *sm;struct soc_bytes_ext *sbe;struct soc_enum *se; -size_t size =0 ;int i;for (i =0 ; i < widget->num_kcontrols; i++) {
@@ -1800,7 +1800,11 @@ static size_t sof_get_control_data(struct snd_sof_dev *sdev,if (wdata[i].pdata->magic !=SOF_ABI_MAGIC )return -EINVAL ; - size += wdata[i].pdata->size; +/* don't accept 0 size for data */ +if (!wdata[i].pdata->size) +return -EINVAL ; + + *size += wdata[i].pdata->size;/* get data type */ switch (wdata[i].control->cmd) {
@@ -1819,7 +1823,7 @@ static size_t sof_get_control_data(struct snd_sof_dev *sdev, } } -return size; +return 0 ; } static int sof_process_load(struct snd_soc_component *scomp, int index,
@@ -1855,12 +1859,11 @@ static int sof_process_load(struct snd_soc_component *scomp, int index,return -ENOMEM ;/* get possible component controls and get size of all pdata */ - ipc_data_size =sof_get_control_data (sdev, widget, wdata); + ret =sof_get_control_data (sdev, widget, wdata, + &ipc_data_size); -if (ipc_data_size <=0 ) { - ret = ipc_data_size; +if (ret <0 ) goto out; - } } ipc_size = sizeof(struct sof_ipc_comp_process) +
Signature · 1 line
2.13.6
Mark Brown
maintainerQuoted 7 lines · Jaska Uimonen
sound/soc/sof/topology.c +4
-0+static int sof_get_control_data (struct snd_sof_dev *sdev, +struct snd_soc_dapm_widget *widget, +struct sof_widget_data *wdata, +size_t *size) {const struct snd_kcontrol_new *kc;struct soc_mixer_control *sm;
sound/soc/sof/topology.c static int sof_widget_load_siggen(struct snd_soc_component *scomp, int index,
Quoted 10 lines
sound/soc/sof/topology.c +3
-2struct soc_bytes_ext *sbe;struct soc_enum *se; -size_t size =0 ;int i; - size += wdata[i].pdata->size; +/* don't accept 0 size for data */ +if (!wdata[i].pdata->size) +return -EINVAL ;
This should really be a separate change.
sound/soc/sof/topology.c static size_t sof_get_control_data(struct snd_sof_dev *sdev, · line 1807
Quoted 2 lines
sound/soc/sof/topology.c +2
-0+ + *size += wdata[i].pdata->size;
We appear to be requiring that the size passed in is zero initialized which is a bit unusual and seems likely to break even if it happens to work right now.
Quoted 23 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Wednesday, August 21, 2019 4:00 PM
To: Jaska Uimonen <[email protected]>
Cc: [email protected]; Uimonen, Jaska <[email protected]>
Subject: Re: [PATCH] ASoC: SOF: topology: fix get control data return type and argumentsQuoted 11 lines · Jaska Uimonen
sound/soc/sof/topology.c +4
-1+static int sof_get_control_data (struct snd_sof_dev *sdev, +struct snd_soc_dapm_widget *widget, +struct sof_widget_data *wdata, +size_t *size) {const struct snd_kcontrol_new *kc;struct soc_mixer_control *sm;struct soc_bytes_ext *sbe;struct soc_enum *se; -size_t size =0 ;int i;
Quoted 6 lines
sound/soc/sof/topology.c static size_t sof_get_control_data(struct snd_sof_dev *sdev, · line 1805
Quoted 4 lines
sound/soc/sof/topology.c +3
-1- size += wdata[i].pdata->size; +/* don't accept 0 size for data */ +if (!wdata[i].pdata->size) +return -EINVAL ;This should really be a separate change.
[Uimonen, Jaska]
Ok will remove from this patch.
Quoted 7 lines
sound/soc/sof/topology.c static size_t sof_get_control_data(struct snd_sof_dev *sdev, · line 1807
Quoted 3 lines
sound/soc/sof/topology.c +2
-0+ + *size += wdata[i].pdata->size;We appear to be requiring that the size passed in is zero initialized which is a bit unusual and seems likely to break even if it happens to work right now.
[Uimonen, Jaska]
Same comments I got from Pierre, obviously I'm not very good listener. Will initialize size to 0.
---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki
Business Identity Code: 0357606 - 4
Domiciled in Helsinki
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.