From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Kent Gibson <warthog618@gmail.com>
Cc: linux-gpio <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod][PATCH v2 2/2] core: fix reading subset of available events
Date: Mon, 14 Sep 2020 10:12:32 +0200 [thread overview]
Message-ID: <CAMpxmJWM4UZ2iDO047-H7sMeCR0BD2exmiMFo3=eF1UmYJZkQA@mail.gmail.com> (raw)
In-Reply-To: <20200912081105.1615496-3-warthog618@gmail.com>
On Sat, Sep 12, 2020 at 10:11 AM Kent Gibson <warthog618@gmail.com> wrote:
>
> Only read the requested number of events from the kernel rather than
> reading up to 16 and quietly discarding any surplus.
>
> The previous behavour is particularly bad for reading single events as
> userspace must read the events as quickly as they arrive, effectively
> negating the presence of the kernel event kfifo.
>
> Fixes: 44921ecc9a00 (core: provide functions for reading multiple
> line events at once)
>
> Signed-off-by: Kent Gibson <warthog618@gmail.com>
> ---
> lib/core.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lib/core.c b/lib/core.c
> index ad76051..b964272 100644
> --- a/lib/core.c
> +++ b/lib/core.c
> @@ -1090,7 +1090,10 @@ int gpiod_line_event_read_fd_multiple(int fd, struct gpiod_line_event *events,
>
> memset(evdata, 0, sizeof(evdata));
>
> - rd = read(fd, evdata, sizeof(evdata));
> + if (num_events > 16)
> + num_events = 16;
> +
> + rd = read(fd, evdata, num_events * sizeof(*evdata));
> if (rd < 0) {
> return -1;
> } else if ((unsigned int)rd < sizeof(*evdata)) {
> --
> 2.28.0
>
Wow this is a bad one, thanks for catching this!
Will apply shortly and backport it to stable branches too.
Thanks!
Bartosz
next prev parent reply other threads:[~2020-09-14 8:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-12 8:11 [libgpiod][PATCH v2 0/2] fix potential discarding of events by read events Kent Gibson
2020-09-12 8:11 ` [libgpiod][PATCH v2 1/2] tests: event: reading test coverage extended to cover reading a subset of available events Kent Gibson
2020-09-12 8:11 ` [libgpiod][PATCH v2 2/2] core: fix reading " Kent Gibson
2020-09-14 8:12 ` Bartosz Golaszewski [this message]
2020-09-14 15:16 ` Andy Shevchenko
2020-09-14 15:20 ` Bartosz Golaszewski
2020-09-14 15:22 ` Andy Shevchenko
2020-09-14 23:33 ` Kent Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMpxmJWM4UZ2iDO047-H7sMeCR0BD2exmiMFo3=eF1UmYJZkQA@mail.gmail.com' \
--to=bgolaszewski@baylibre.com \
--cc=linux-gpio@vger.kernel.org \
--cc=warthog618@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.