diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-10-13 05:52:16 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-10-13 06:02:20 -0400 |
commit | 2b194f9db444875b4509e6dc92c949c57437c826 (patch) | |
tree | eea3cda954998bf4a37d6c56c1f06fcf309f0d62 /sound/soc | |
parent | 4abe8e16a8ad879027de3a0a088f281577ad24a9 (diff) |
ASoC: Check list debugfs files for PAGE_SIZE overflow
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'sound/soc')
-rw-r--r-- | sound/soc/soc-core.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 225b5bd2802e..6cee97e23da6 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c | |||
@@ -274,15 +274,22 @@ static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, | |||
274 | size_t count, loff_t *ppos) | 274 | size_t count, loff_t *ppos) |
275 | { | 275 | { |
276 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | 276 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
277 | ssize_t ret = 0; | 277 | ssize_t len, ret = 0; |
278 | struct snd_soc_codec *codec; | 278 | struct snd_soc_codec *codec; |
279 | 279 | ||
280 | if (!buf) | 280 | if (!buf) |
281 | return -ENOMEM; | 281 | return -ENOMEM; |
282 | 282 | ||
283 | list_for_each_entry(codec, &codec_list, list) | 283 | list_for_each_entry(codec, &codec_list, list) { |
284 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", | 284 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
285 | codec->name); | 285 | codec->name); |
286 | if (len >= 0) | ||
287 | ret += len; | ||
288 | if (ret > PAGE_SIZE) { | ||
289 | ret = PAGE_SIZE; | ||
290 | break; | ||
291 | } | ||
292 | } | ||
286 | 293 | ||
287 | if (ret >= 0) | 294 | if (ret >= 0) |
288 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); | 295 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
@@ -301,17 +308,23 @@ static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, | |||
301 | size_t count, loff_t *ppos) | 308 | size_t count, loff_t *ppos) |
302 | { | 309 | { |
303 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | 310 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
304 | ssize_t ret = 0; | 311 | ssize_t len, ret = 0; |
305 | struct snd_soc_dai *dai; | 312 | struct snd_soc_dai *dai; |
306 | 313 | ||
307 | if (!buf) | 314 | if (!buf) |
308 | return -ENOMEM; | 315 | return -ENOMEM; |
309 | 316 | ||
310 | list_for_each_entry(dai, &dai_list, list) | 317 | list_for_each_entry(dai, &dai_list, list) { |
311 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); | 318 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); |
319 | if (len >= 0) | ||
320 | ret += len; | ||
321 | if (ret > PAGE_SIZE) { | ||
322 | ret = PAGE_SIZE; | ||
323 | break; | ||
324 | } | ||
325 | } | ||
312 | 326 | ||
313 | if (ret >= 0) | 327 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
314 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); | ||
315 | 328 | ||
316 | kfree(buf); | 329 | kfree(buf); |
317 | 330 | ||
@@ -328,18 +341,24 @@ static ssize_t platform_list_read_file(struct file *file, | |||
328 | size_t count, loff_t *ppos) | 341 | size_t count, loff_t *ppos) |
329 | { | 342 | { |
330 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | 343 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
331 | ssize_t ret = 0; | 344 | ssize_t len, ret = 0; |
332 | struct snd_soc_platform *platform; | 345 | struct snd_soc_platform *platform; |
333 | 346 | ||
334 | if (!buf) | 347 | if (!buf) |
335 | return -ENOMEM; | 348 | return -ENOMEM; |
336 | 349 | ||
337 | list_for_each_entry(platform, &platform_list, list) | 350 | list_for_each_entry(platform, &platform_list, list) { |
338 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", | 351 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
339 | platform->name); | 352 | platform->name); |
353 | if (len >= 0) | ||
354 | ret += len; | ||
355 | if (ret > PAGE_SIZE) { | ||
356 | ret = PAGE_SIZE; | ||
357 | break; | ||
358 | } | ||
359 | } | ||
340 | 360 | ||
341 | if (ret >= 0) | 361 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
342 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); | ||
343 | 362 | ||
344 | kfree(buf); | 363 | kfree(buf); |
345 | 364 | ||