linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH next] sysfs: fix sysfs_write_file for bin file
@ 2013-10-23 13:44 Ming Lei
  2013-10-24 10:31 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Ming Lei @ 2013-10-23 13:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, Lothar Waßmann, Ming Lei, Tejun Heo

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-and-tested-by: Lothar Waßmann <LW@karo-electronics.de>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Ming Lei <ming.lei@canonical.com>
---
 fs/sysfs/file.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 5d818df..c379597 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -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);
 	ssize_t len = min_t(size_t, count, PAGE_SIZE);
+	loff_t size = file_inode(file)->i_size;
 	char *buf;
 
-	if (sysfs_is_bin(of->sd)) {
-		loff_t size = file_inode(file)->i_size;
-
+	if (sysfs_is_bin(of->sd) && size) {
 		if (size <= *ppos)
 			return 0;
 		len = min_t(ssize_t, len, size - *ppos);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH next] sysfs: fix sysfs_write_file for bin file
  2013-10-23 13:44 [PATCH next] sysfs: fix sysfs_write_file for bin file Ming Lei
@ 2013-10-24 10:31 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2013-10-24 10:31 UTC (permalink / raw)
  To: Ming Lei; +Cc: Greg Kroah-Hartman, linux-kernel, Lothar Waßmann

On Wed, Oct 23, 2013 at 09:44:53PM +0800, Ming Lei wrote:
> 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-and-tested-by: Lothar Waßmann <LW@karo-electronics.de>
> Cc: Tejun Heo <tj@kernel.org>
> Signed-off-by: Ming Lei <ming.lei@canonical.com>

Oops, sorry about missing that.

  Acked-by: Tejun Heo <tj@kernel.org>

Thanks!

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-10-24 10:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-23 13:44 [PATCH next] sysfs: fix sysfs_write_file for bin file Ming Lei
2013-10-24 10:31 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).