* [PATCH] gpio: mockup: use simple_read_from_buffer() in debugfs read callback
@ 2019-03-28 11:00 Bartosz Golaszewski
2019-03-28 13:11 ` Mukesh Ojha
0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2019-03-28 11:00 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
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")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/gpio/gpio-mockup.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index 74ba8b1d71d8..859585dce5c9 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -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,
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] gpio: mockup: use simple_read_from_buffer() in debugfs read callback
2019-03-28 11:00 [PATCH] gpio: mockup: use simple_read_from_buffer() in debugfs read callback Bartosz Golaszewski
@ 2019-03-28 13:11 ` Mukesh Ojha
2019-03-28 13:42 ` Bartosz Golaszewski
0 siblings, 1 reply; 3+ messages in thread
From: Mukesh Ojha @ 2019-03-28 13:11 UTC (permalink / raw)
To: Bartosz Golaszewski, Linus Walleij
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
On 3/28/2019 4:30 PM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> 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")
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
> drivers/gpio/gpio-mockup.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
> index 74ba8b1d71d8..859585dce5c9 100644
> --- a/drivers/gpio/gpio-mockup.c
> +++ b/drivers/gpio/gpio-mockup.c
> @@ -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.
>
> - 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.
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
-Mukesh
> }
>
> static ssize_t gpio_mockup_debugfs_write(struct file *file,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gpio: mockup: use simple_read_from_buffer() in debugfs read callback
2019-03-28 13:11 ` Mukesh Ojha
@ 2019-03-28 13:42 ` Bartosz Golaszewski
0 siblings, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2019-03-28 13:42 UTC (permalink / raw)
To: Mukesh Ojha
Cc: Linus Walleij, open list:GPIO SUBSYSTEM,
Linux Kernel Mailing List, Bartosz Golaszewski
czw., 28 mar 2019 o 14:11 Mukesh Ojha <mojha@codeaurora.org> napisał(a):
>
>
> On 3/28/2019 4:30 PM, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > 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")
> > Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> > ---
> > drivers/gpio/gpio-mockup.c | 7 +------
> > 1 file changed, 1 insertion(+), 6 deletions(-)
> >
> > diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
> > index 74ba8b1d71d8..859585dce5c9 100644
> > --- a/drivers/gpio/gpio-mockup.c
> > +++ b/drivers/gpio/gpio-mockup.c
> > @@ -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'.
> rv variable is unused now.
>
> >
> > - 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.
>
Thanks, removed that and a stray newline.
Bart
> Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
>
> -Mukesh
>
> > }
> >
> > static ssize_t gpio_mockup_debugfs_write(struct file *file,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-03-28 13:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-28 11:00 [PATCH] gpio: mockup: use simple_read_from_buffer() in debugfs read callback Bartosz Golaszewski
2019-03-28 13:11 ` Mukesh Ojha
2019-03-28 13:42 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).