Skip to contentSkip to conversation

gpio: mockup: use simple_read_from_buffer() in debugfs read callback

PATCH In review Bartosz Golaszewski 2 participants 3 messages Mar 28, 2019

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

PATCH 1/1 gpio: mockup: use simple_read_from_buffer() in debugfs read callback

From: Bartosz Golaszewski <[email protected]>

Calling read() for a single byte read will return 2 currently. Use simple_read_from_buffer() which correctly handles all sizes.

Fixes 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
---
 drivers/gpio/gpio-mockup.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpio-mockup.c +1 -6
index 74ba8b1d71d8..859585dce5c9 100644
@@ -219,12 +219,7 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file,
 	val = gpio_mockup_get(gc, priv->offset);
 	cnt = snprintf(buf, sizeof(buf), "%d\n", val);
 
-	rv = copy_to_user(usr_buf, buf, cnt);
-	if (rv)
-		return rv;
-
-	*ppos += cnt;
-	return cnt;
+	return simple_read_from_buffer(usr_buf, size, ppos, buf, cnt);
 }
 
 static ssize_t gpio_mockup_debugfs_write(struct file *file,
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Calling read() for a single byte read will return 2 currently. Use simple_read_from_buffer() which correctly handles all sizes.

Fixes 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
---
  drivers/gpio/gpio-mockup.c | 7 +------
  1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpio-mockup.c +0 -0
index 74ba8b1d71d8..859585dce5c9 100644

drivers/gpio/gpio-mockup.c static ssize_t gpio_mockup_debugfs_read(struct file *file, · line 220

Quoted 2 lines
drivers/gpio/gpio-mockup.c +0 -0
@@ -219,12 +219,7 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file,
  	val = gpio_mockup_get(gc, priv->offset);
  	cnt = snprintf(buf, sizeof(buf), "%d\n", val);

why \n is inserted in the buf..

rv variable is unused now.

drivers/gpio/gpio-mockup.c static ssize_t gpio_mockup_debugfs_read(struct file *file, · line 222

Quoted 8 lines
drivers/gpio/gpio-mockup.c +1 -6
-	rv = copy_to_user(usr_buf, buf, cnt);
-	if (rv)
-		return rv;
-
-	*ppos += cnt;
-	return cnt;
+	return simple_read_from_buffer(usr_buf, size, ppos, buf, cnt);

Looks good to me.
Remove the unused variable.

-Mukesh

Quoted 3 lines
drivers/gpio/gpio-mockup.c +0 -0
  }
 
  static ssize_t gpio_mockup_debugfs_write(struct file *file,
#2 lore raw

czw., 28 mar 2019 o 14:11 Mukesh Ojha <[email protected]> napisał(a):

Quoted 14 lines · Bartosz Golaszewski
Quoted 11 lines

From: Bartosz Golaszewski <[email protected]>

Calling read() for a single byte read will return 2 currently. Use simple_read_from_buffer() which correctly handles all sizes.

Fixes 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
---
  drivers/gpio/gpio-mockup.c | 7 +------
  1 file changed, 1 insertion(+), 6 deletions(-)
Quoted 11 lines

drivers/gpio/gpio-mockup.c static ssize_t gpio_mockup_debugfs_read(struct file *file, · line 220

Quoted 7 lines
drivers/gpio/gpio-mockup.c +0 -0
index 74ba8b1d71d8..859585dce5c9 100644
@@ -219,12 +219,7 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file,
      val = gpio_mockup_get(gc, priv->offset);
      cnt = snprintf(buf, sizeof(buf), "%d\n", val);

why \n is inserted in the buf..

Because this is how all the attributes work - you read the value + '\n'.

Quoted 13 lines

rv variable is unused now.

drivers/gpio/gpio-mockup.c static ssize_t gpio_mockup_debugfs_read(struct file *file, · line 222

Quoted 8 lines
drivers/gpio/gpio-mockup.c +1 -6
-     rv = copy_to_user(usr_buf, buf, cnt);
-     if (rv)
-             return rv;
-
-     *ppos += cnt;
-     return cnt;
+     return simple_read_from_buffer(usr_buf, size, ppos, buf, cnt);
Quoted 3 lines

Looks good to me.
Remove the unused variable.

Thanks, removed that and a stray newline.

Bart

Quoted 7 lines

-Mukesh

Quoted 3 lines
drivers/gpio/gpio-mockup.c +0 -0
  }
 
  static ssize_t gpio_mockup_debugfs_write(struct file *file,