kernel: update kernel 4.4 to 4.4.59
[openwrt/staging/dedeckeh.git] / target / linux / brcm2708 / patches-4.4 / 0568-configfs-Remove-ppos-increment-in-configfs_write_bin.patch
1 From b928add95c9ddaa70b591da00d129558535d14d3 Mon Sep 17 00:00:00 2001
2 From: Marek Vasut <marex@denx.de>
3 Date: Wed, 18 May 2016 16:16:51 +0200
4 Subject: [PATCH] configfs: Remove ppos increment in configfs_write_bin_file
5
6 [ Back-port of f8608985f851c917b3884b692d8e326b0210d34e ]
7
8 The simple_write_to_buffer() already increments the @ppos on success,
9 see fs/libfs.c simple_write_to_buffer() comment:
10
11 "
12 On success, the number of bytes written is returned and the offset @ppos
13 advanced by this number, or negative value is returned on error.
14 "
15
16 If the configfs_write_bin_file() is invoked with @count smaller than the
17 total length of the written binary file, it will be invoked multiple times.
18 Since configfs_write_bin_file() increments @ppos on success, after calling
19 simple_write_to_buffer(), the @ppos is incremented twice.
20
21 Subsequent invocation of configfs_write_bin_file() will result in the next
22 piece of data being written to the offset twice as long as the length of
23 the previous write, thus creating buffer with "holes" in it.
24
25 The simple testcase using DTO follows:
26 $ mkdir /sys/kernel/config/device-tree/overlays/1
27 $ dd bs=1 if=foo.dtbo of=/sys/kernel/config/device-tree/overlays/1/dtbo
28 Without this patch, the testcase will result in twice as big buffer in the
29 kernel, which is then passed to the cfs_overlay_item_dtbo_write() .
30
31 Signed-off-by: Marek Vasut <marex@denx.de>
32 Cc: Geert Uytterhoeven <geert+renesas@glider.be>
33 Cc: Christoph Hellwig <hch@lst.de>
34 Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
35 ---
36 fs/configfs/file.c | 2 --
37 1 file changed, 2 deletions(-)
38
39 --- a/fs/configfs/file.c
40 +++ b/fs/configfs/file.c
41 @@ -357,8 +357,6 @@ configfs_write_bin_file(struct file *fil
42
43 len = simple_write_to_buffer(buffer->bin_buffer,
44 buffer->bin_buffer_size, ppos, buf, count);
45 - if (len > 0)
46 - *ppos += len;
47 out:
48 mutex_unlock(&buffer->mutex);
49 return len;