Commit ce57e981 authored by Linus Torvalds's avatar Linus Torvalds

firmware: use 'kernel_read()' to read firmware into kernel buffer

Fengguang correctly points out that the firmware reading should not use
vfs_read(), since the buffer is in kernel space.

The vfs_read() just happened to work for kernel threads, but sparse
warns about the incorrect address spaces, and it's definitely incorrect
and could fail for other users of the firmware loading.
Reported-by: default avatarFengguang Wu <fengguang.wu@intel.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e1cc4852
...@@ -58,7 +58,6 @@ static noinline long fw_file_size(struct file *file) ...@@ -58,7 +58,6 @@ static noinline long fw_file_size(struct file *file)
static bool fw_read_file_contents(struct file *file, struct firmware *fw) static bool fw_read_file_contents(struct file *file, struct firmware *fw)
{ {
loff_t pos;
long size; long size;
char *buf; char *buf;
...@@ -68,8 +67,7 @@ static bool fw_read_file_contents(struct file *file, struct firmware *fw) ...@@ -68,8 +67,7 @@ static bool fw_read_file_contents(struct file *file, struct firmware *fw)
buf = vmalloc(size); buf = vmalloc(size);
if (!buf) if (!buf)
return false; return false;
pos = 0; if (kernel_read(file, 0, buf, size) != size) {
if (vfs_read(file, buf, size, &pos) != size) {
vfree(buf); vfree(buf);
return false; return false;
} }
......
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