Commit 2b194f9d authored by Mark Brown's avatar Mark Brown

ASoC: Check list debugfs files for PAGE_SIZE overflow

Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
parent 4abe8e16
...@@ -274,15 +274,22 @@ static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, ...@@ -274,15 +274,22 @@ static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
ssize_t ret = 0; ssize_t len, ret = 0;
struct snd_soc_codec *codec; struct snd_soc_codec *codec;
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
list_for_each_entry(codec, &codec_list, list) list_for_each_entry(codec, &codec_list, list) {
ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
codec->name); codec->name);
if (len >= 0)
ret += len;
if (ret > PAGE_SIZE) {
ret = PAGE_SIZE;
break;
}
}
if (ret >= 0) if (ret >= 0)
ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
...@@ -301,16 +308,22 @@ static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, ...@@ -301,16 +308,22 @@ static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
ssize_t ret = 0; ssize_t len, ret = 0;
struct snd_soc_dai *dai; struct snd_soc_dai *dai;
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
list_for_each_entry(dai, &dai_list, list) list_for_each_entry(dai, &dai_list, list) {
ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
if (len >= 0)
ret += len;
if (ret > PAGE_SIZE) {
ret = PAGE_SIZE;
break;
}
}
if (ret >= 0)
ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
kfree(buf); kfree(buf);
...@@ -328,17 +341,23 @@ static ssize_t platform_list_read_file(struct file *file, ...@@ -328,17 +341,23 @@ static ssize_t platform_list_read_file(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
ssize_t ret = 0; ssize_t len, ret = 0;
struct snd_soc_platform *platform; struct snd_soc_platform *platform;
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
list_for_each_entry(platform, &platform_list, list) list_for_each_entry(platform, &platform_list, list) {
ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
platform->name); platform->name);
if (len >= 0)
ret += len;
if (ret > PAGE_SIZE) {
ret = PAGE_SIZE;
break;
}
}
if (ret >= 0)
ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
kfree(buf); kfree(buf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment