[igt-dev] [PATCH i-g-t] lib/igt_kms: Fix igt_display_drop_events() to work as intended
Chris Wilson
chris at chris-wilson.co.uk
Thu Feb 15 12:03:25 UTC 2018
Quoting Maarten Lankhorst (2018-02-15 11:49:17)
> 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 at intel.com>
> Reported-by: Jari Tahvanainen <jari.tahvanainen at intel.com>
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst at 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);
Fwiw ^ that was the bug.
> - 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]) {
struct drm_event *ev = (struct drm_event *)(buf +i);
gets rid of the other two struct drm_event ev assignments
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
-Chris
More information about the igt-dev
mailing list