gpio: mockup: use simple_read_from_buffer() in debugfs read callback
Subsystems (2)
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.
--- drivers/gpio/gpio-mockup.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpio-mockup.c +1 -6
@@ -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
Quoted 16 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Calling
read()for a single byte read will return 2 currently. Usesimple_read_from_buffer()which correctly handles all sizes.Fixes 2a9e27408e12 ("gpio: mockup: rework debugfs interface")Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/gpio/gpio-mockup.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)drivers/gpio/gpio-mockup.c +0
-0
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,
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. Usesimple_read_from_buffer()which correctly handles all sizes.Fixes 2a9e27408e12 ("gpio: mockup: rework debugfs interface")Signed-off-by Bartosz Golaszewski <[email protected]>--- 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@@ -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
Reviewed-by Mukesh Ojha <[email protected]>-Mukesh
Quoted 3 lines
drivers/gpio/gpio-mockup.c +0
-0} static ssize_t gpio_mockup_debugfs_write(struct file *file,