Commit b9c06225 authored by Ming Lei's avatar Ming Lei Committed by Greg Kroah-Hartman

sysfs: fix sysfs_write_file for bin file

Before patch(sysfs: prepare path write for unified regular / bin
file handling), when size of bin file is zero, writting still can
continue, but this patch changes the behaviour.

The worse thing is that firmware loader is broken by this patch,
and user space application can't write to firmware bin file any more
because both firmware loader and drivers can't know at advance how
large the firmware file is and have to set its initialized size as
zero.

This patch fixes the problem and keeps behaviour of writting to bin
as before.
Reported-by: default avatarLothar Waßmann <LW@karo-electronics.de>
Tested-by: default avatarLothar Waßmann <LW@karo-electronics.de>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarMing Lei <ming.lei@canonical.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0cba7de7
...@@ -275,11 +275,10 @@ static ssize_t sysfs_write_file(struct file *file, const char __user *user_buf, ...@@ -275,11 +275,10 @@ static ssize_t sysfs_write_file(struct file *file, const char __user *user_buf,
{ {
struct sysfs_open_file *of = sysfs_of(file); struct sysfs_open_file *of = sysfs_of(file);
ssize_t len = min_t(size_t, count, PAGE_SIZE); ssize_t len = min_t(size_t, count, PAGE_SIZE);
loff_t size = file_inode(file)->i_size;
char *buf; char *buf;
if (sysfs_is_bin(of->sd)) { if (sysfs_is_bin(of->sd) && size) {
loff_t size = file_inode(file)->i_size;
if (size <= *ppos) if (size <= *ppos)
return 0; return 0;
len = min_t(ssize_t, len, size - *ppos); len = min_t(ssize_t, len, size - *ppos);
......
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