Skip to contentSkip to conversation

gpio: mockup: fix debugfs read

PATCH In review Bartosz Golaszewski 3 participants 5 messages Mar 22, 2019 – Mar 28, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: mockup: fix debugfs read

From: Bartosz Golaszewski <[email protected]>

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 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
---
 drivers/gpio/gpio-mockup.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpio/gpio-mockup.c +6 -4
index 154d959e8993..74ba8b1d71d8 100644
@@ -204,8 +204,9 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file,
 	struct gpio_mockup_chip *chip;
 	struct seq_file *sfile;
 	struct gpio_chip *gc;
+	int val, rv, cnt;
 	char buf[3];
-	int val, rv;
+
 
 	if (*ppos != 0)
 		return 0;
@@ -216,13 +217,14 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file,
 	gc = &chip->gc;
 
 	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)
 		return rv;
 
-	return sizeof(buf) - 1;
+	*ppos += cnt;
+	return cnt;
 }
 
 static ssize_t gpio_mockup_debugfs_write(struct file *file,
Signature · 1 line
2.20.1
#1 lore raw
Quoted 9 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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 2a9e27408e12 ("gpio: mockup: rework debugfs interface")

Patch applied for fixes.
Sorry for slow application, I was in no-wifi-land for some days.

Yours,
Linus Walleij

#2 lore raw

czw., 28 mar 2019 o 17:38 Linus Walleij <[email protected]> napisał(a):

Quoted 10 lines · Bartosz Golaszewski
Quoted 8 lines

From: Bartosz Golaszewski <[email protected]>

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.

Quoted 8 lines
Quoted 2 lines
Fixes 2a9e27408e12 ("gpio: mockup: rework debugfs interface")

Patch applied for fixes.
Sorry for slow application, I was in no-wifi-land for some days.

Yours,
Linus Walleij

Ugh, I was thinking about sending you a pull-request with this and a subsequent fix this evening. Plus other fixes I have in my tree.

Bart

#3 lore raw
Quoted 13 lines · Bartosz Golaszewski

czw., 28 mar 2019 o 17:38 Linus Walleij <[email protected]> napisał(a):

Quoted 12 lines · Bartosz Golaszewski
Quoted 10 lines

From: Bartosz Golaszewski <[email protected]>

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 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
Quoted 8 lines
Quoted 5 lines

Patch applied for fixes.
Sorry for slow application, I was in no-wifi-land for some days.

Yours,
Linus Walleij

Ugh, I was thinking about sending you a pull-request with this and a subsequent fix this evening. Plus other fixes I have in my tree.

Oh if it is easier for you do that, and I will drop this patch and just merge your PR as it arrives.

Yours,
Linus Walleij

#4 lore raw

czw., 28 mar 2019 o 17:56 Linus Walleij <[email protected]> napisał(a):

Quoted 21 lines · Bartosz Golaszewski
Quoted 19 lines

czw., 28 mar 2019 o 17:38 Linus Walleij <[email protected]> napisał(a):

Quoted 17 lines · Bartosz Golaszewski
Quoted 10 lines

From: Bartosz Golaszewski <[email protected]>

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 2a9e27408e12 ("gpio: mockup: rework debugfs interface")

Patch applied for fixes.
Sorry for slow application, I was in no-wifi-land for some days.

Yours,
Linus Walleij

Quoted 8 lines
Quoted 2 lines

Ugh, I was thinking about sending you a pull-request with this and a subsequent fix this evening. Plus other fixes I have in my tree.

Oh if it is easier for you do that, and I will drop this patch and just merge your PR as it arrives.

Yours,
Linus Walleij

Yes, let's do it.

Bart