0568-configfs-Remove-ppos-increment-in-configfs_write_bin.patch 1.8 KB

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