Commit 2583303d authored by Bartosz Golaszewski's avatar Bartosz Golaszewski

gpio: mockup: fix debugfs read

The debugfs read callback must advance ppos or users using read() on
the file descriptor will never get the EOL. This wasn't spotted before
as I was using busybox cat for testing which uses sendfile() internally
and only noticed it now when switched to cat from coreutils.

Fixes: 2a9e2740 ("gpio: mockup: rework debugfs interface")
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
parent fa59dd23
...@@ -204,8 +204,9 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file, ...@@ -204,8 +204,9 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file,
struct gpio_mockup_chip *chip; struct gpio_mockup_chip *chip;
struct seq_file *sfile; struct seq_file *sfile;
struct gpio_chip *gc; struct gpio_chip *gc;
int val, rv, cnt;
char buf[3]; char buf[3];
int val, rv;
if (*ppos != 0) if (*ppos != 0)
return 0; return 0;
...@@ -216,13 +217,14 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file, ...@@ -216,13 +217,14 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file,
gc = &chip->gc; gc = &chip->gc;
val = gpio_mockup_get(gc, priv->offset); val = gpio_mockup_get(gc, priv->offset);
snprintf(buf, sizeof(buf), "%d\n", val); cnt = snprintf(buf, sizeof(buf), "%d\n", val);
rv = copy_to_user(usr_buf, buf, sizeof(buf)); rv = copy_to_user(usr_buf, buf, cnt);
if (rv) if (rv)
return rv; return rv;
return sizeof(buf) - 1; *ppos += cnt;
return cnt;
} }
static ssize_t gpio_mockup_debugfs_write(struct file *file, static ssize_t gpio_mockup_debugfs_write(struct file *file,
......
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