Skip to content

Commit

Permalink
firmware: use 'kernel_read()' to read firmware into kernel buffer
Browse files Browse the repository at this point in the history
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: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Linus Torvalds committed Oct 4, 2012
1 parent e1cc485 commit ce57e98
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions drivers/base/firmware_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
loff_t pos;
long size;
char *buf;

Expand All @@ -68,8 +67,7 @@ static bool fw_read_file_contents(struct file *file, struct firmware *fw)
buf = vmalloc(size);
if (!buf)
return false;
pos = 0;
if (vfs_read(file, buf, size, &pos) != size) {
if (kernel_read(file, 0, buf, size) != size) {
vfree(buf);
return false;
}
Expand Down

0 comments on commit ce57e98

Please sign in to comment.