From: Kent Gibson <warthog618@gmail.com>
To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com
Cc: Kent Gibson <warthog618@gmail.com>
Subject: [libgpiod][PATCH 2/2] core: fix reading subset of available events
Date: Sat, 12 Sep 2020 10:22:48 +0800 [thread overview]
Message-ID: <20200912022248.16240-3-warthog618@gmail.com> (raw)
In-Reply-To: <20200912022248.16240-1-warthog618@gmail.com>
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
prev parent reply other threads:[~2020-09-12 2:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-12 2:22 [libgpiod][PATCH 0/2] fix potential discarding of events by read events Kent Gibson
2020-09-12 2:22 ` [libgpiod][PATCH 1/2] tests: event: reading test coverage extended to cover reading a subset of available events Kent Gibson
2020-09-12 3:54 ` Kent Gibson
2020-09-12 2:22 ` Kent Gibson [this message]
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=20200912022248.16240-3-warthog618@gmail.com \
--to=warthog618@gmail.com \
--cc=bgolaszewski@baylibre.com \
--cc=linux-gpio@vger.kernel.org \
/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 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).