Skip to content

Commit e42535d

Browse files
committed
fixup! ASoC: SOF: fix range checks
The mix of integer and size_t generates different results in 32- and 64 bit mode, cast to size_t and use %zu format. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
1 parent 48ded78 commit e42535d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

sound/soc/sof/control.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
232232
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
233233
if (data->size > be->max - sizeof(*data)) {
234234
dev_err_ratelimited(scomp->dev,
235-
"error: %u bytes of control data is invalid, max is %lu\n",
236-
data->size, be->max - sizeof(*data));
235+
"error: %u bytes of control data is invalid, max is %zu\n",
236+
data->size, (size_t)be->max - sizeof(*data));
237237
return -EINVAL;
238238
}
239239

@@ -266,8 +266,8 @@ int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
266266
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
267267
if (data->size > be->max - sizeof(*data)) {
268268
dev_err_ratelimited(scomp->dev,
269-
"error: data size too big %u bytes max is %lu\n",
270-
data->size, be->max - sizeof(*data));
269+
"error: data size too big %u bytes max is %zu\n",
270+
data->size, (size_t)be->max - sizeof(*data));
271271
return -EINVAL;
272272
}
273273

@@ -441,8 +441,9 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
441441

442442
/* check data size doesn't exceed max coming from topology */
443443
if (cdata->data->size > be->max - sizeof(const struct sof_abi_hdr)) {
444-
dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %lu.\n",
445-
cdata->data->size, be->max - sizeof(const struct sof_abi_hdr));
444+
dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %zu.\n",
445+
cdata->data->size,
446+
(size_t)be->max - sizeof(const struct sof_abi_hdr));
446447
return -EINVAL;
447448
}
448449

sound/soc/sof/topology.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,8 @@ static int sof_control_load_bytes(struct snd_soc_component *scomp,
11621162

11631163
/* init the get/put bytes data */
11641164
if (priv_size > max_size - sizeof(struct sof_ipc_ctrl_data)) {
1165-
dev_err(scomp->dev, "err: bytes data size %lu exceeds max %lu.\n",
1166-
priv_size, max_size - sizeof(struct sof_ipc_ctrl_data));
1165+
dev_err(scomp->dev, "err: bytes data size %zu exceeds max %zu.\n",
1166+
priv_size, (size_t)max_size - sizeof(struct sof_ipc_ctrl_data));
11671167
ret = -EINVAL;
11681168
goto out;
11691169
}

0 commit comments

Comments
 (0)