aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kalauskas <peskal@google.com>2018-08-21 21:54:02 -0700
committerAmit Pundir <amit.pundir@linaro.org>2018-10-04 14:16:25 +0530
commit4e04ef38baf1f3090c39477f6150675a0f183949 (patch)
treeb3168795bbb1d681810e09f4058c0ea25e81aa3d
parentd8ea3525da54d73b5d69fa44999b01a857209060 (diff)
downloadlinaro-android-4e04ef38baf1f3090c39477f6150675a0f183949.tar.gz
UPSTREAM: drivers/block/zram/zram_drv.c: fix bug storing backing_dev
The call to strlcpy in backing_dev_store is incorrect. It should take the size of the destination buffer instead of the size of the source buffer. Additionally, ignore the newline character (\n) when reading the new file_name buffer. This makes it possible to set the backing_dev as follows: echo /dev/sdX > /sys/block/zram0/backing_dev The reason it worked before was the fact that strlcpy() copies 'len - 1' bytes, which is strlen(buf) - 1 in our case, so it accidentally didn't copy the trailing new line symbol. Which also means that "echo -n /dev/sdX" most likely was broken. Signed-off-by: Peter Kalauskas <peskal@google.com> Link: http://lkml.kernel.org/r/20180813061623.GC64836@rodete-desktop-imager.corp.google.com Acked-by: Minchan Kim <minchan@kernel.org> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: <stable@vger.kernel.org> [4.14+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> (cherry picked from commit c8bd134a4bddafe5917d163eea73873932c15e83) Signed-off-by: Peter Kalauskas <peskal@google.com> Bug: 112488418 Change-Id: I0a0d602b61169ae9adc8f89914ce4e30cc10e191 Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
-rw-r--r--drivers/block/zram/zram_drv.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 5d8abb87eed2..ec034123cbec 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -339,6 +339,7 @@ static ssize_t backing_dev_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
{
char *file_name;
+ size_t sz;
struct file *backing_dev = NULL;
struct inode *inode;
struct address_space *mapping;
@@ -360,7 +361,11 @@ static ssize_t backing_dev_store(struct device *dev,
goto out;
}
- strlcpy(file_name, buf, len);
+ strlcpy(file_name, buf, PATH_MAX);
+ /* ignore trailing newline */
+ sz = strlen(file_name);
+ if (sz > 0 && file_name[sz - 1] == '\n')
+ file_name[sz - 1] = 0x00;
backing_dev = filp_open(file_name, O_RDWR|O_LARGEFILE, 0);
if (IS_ERR(backing_dev)) {