All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t] lib/igt_kms: Fix igt_display_drop_events() to work as intended
@ 2018-02-15 11:49 Maarten Lankhorst
  2018-02-15 12:03 ` Chris Wilson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Maarten Lankhorst @ 2018-02-15 11:49 UTC (permalink / raw)
  To: igt-dev; +Cc: Jari Tahvanainen

Short reads don't work, you either read the whole event or nothing
at all, so follow the recommendations in the documentation and
allocate a buffer of 4096 bytes for the event, if we capture
multiple events read them all.

Cc: Jari Tahvanainen <jari.tahvanainen@intel.com>
Reported-by: Jari Tahvanainen <jari.tahvanainen@intel.com>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104538
---
 lib/igt_kms.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 11f23fcaaa81..5a5df61c5856 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -3228,14 +3228,18 @@ int igt_display_drop_events(igt_display_t *display)
 	};
 
 	while (poll(&pfd, 1, 0) > 0) {
-		struct drm_event ev;
-		char buf[128];
-
-		read(display->drm_fd, &ev, sizeof(ev));
-		igt_info("Dropping event type %u length %u\n", ev.type, ev.length);
-		igt_assert(ev.length <= sizeof(buf));
-		read(display->drm_fd, buf, ev.length);
-		ret++;
+		char buf[4096];
+		ssize_t retval;
+		struct drm_event *ev = (struct drm_event *)buf;
+
+		retval = read(display->drm_fd, &buf, sizeof(buf));
+		igt_assert_lt(0, retval);
+
+		for (int i = 0; i < retval; i += ev->length, ev = (struct drm_event *)&buf[i]) {
+			igt_info("Dropping event type %u length %u\n", ev->type, ev->length);
+			igt_assert(ev->length + i <= sizeof(buf));
+			ret++;
+		}
 	}
 
 	return ret;
-- 
2.16.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-02-15 21:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-15 11:49 [igt-dev] [PATCH i-g-t] lib/igt_kms: Fix igt_display_drop_events() to work as intended Maarten Lankhorst
2018-02-15 12:03 ` Chris Wilson
2018-02-15 13:52   ` Maarten Lankhorst
2018-02-15 13:30 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2018-02-15 21:32 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork

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.