[PATCH libevdev] Update struct input_event

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 12 06:05:07 UTC 2018


On Mon, Jan 15, 2018 at 04:21:08PM -0800, Deepa Dinamani wrote:
> The struct input_event is not y2038 safe.
> Update the struct according to the kernel patch:
> https://lkml.org/lkml/2018/1/6/324
> 
> Signed-off-by: Deepa Dinamani <deepa.kernel at gmail.com>

this one is now in libevdev as 3c6766c86246c1594096b23e769079e639fc75ad,
thanks.

Cheers,
   Peter

> ---
>  include/linux/input.h     | 13 ++++++++++++-
>  libevdev/libevdev.c       |  6 ++++--
>  test/test-libevdev-init.c | 20 ++++++++++----------
>  tools/libevdev-events.c   |  8 ++++----
>  tools/mouse-dpi-tool.c    |  8 +-------
>  5 files changed, 31 insertions(+), 24 deletions(-)
> 
> diff --git a/include/linux/input.h b/include/linux/input.h
> index c5c8bc4..8274c29 100644
> --- a/include/linux/input.h
> +++ b/include/linux/input.h
> @@ -1,3 +1,4 @@
> +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
>  /*
>   * Copyright (c) 1999-2002 Vojtech Pavlik
>   *
> @@ -18,10 +19,20 @@
>  
>  /*
>   * The event structure itself
> + * Note that __USE_TIME_BITS64 is defined by libc based on
> + * application's request to use 64 bit time_t.
>   */
> -
>  struct input_event {
> +#if	(__BITS_PER_LONG != 32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL)
>  	struct timeval time;
> +#define input_event_sec time.tv_sec
> +#define input_event_usec time.tv_usec
> +#else
> +	__kernel_ulong_t __sec;
> +	__kernel_ulong_t __usec;
> +#define input_event_sec  __sec
> +#define input_event_usec __usec
> +#endif
>  	__u16 type;
>  	__u16 code;
>  	__s32 value;
> diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
> index 41bfd25..a48974f 100644
> --- a/libevdev/libevdev.c
> +++ b/libevdev/libevdev.c
> @@ -524,7 +524,8 @@ libevdev_get_fd(const struct libevdev* dev)
>  static inline void
>  init_event(struct libevdev *dev, struct input_event *ev, int type, int code, int value)
>  {
> -	ev->time = dev->last_event_time;
> +	ev->input_event_sec = dev->last_event_time.tv_sec;
> +	ev->input_event_usec = dev->last_event_time.tv_usec;
>  	ev->type = type;
>  	ev->code = code;
>  	ev->value = value;
> @@ -966,7 +967,8 @@ update_state(struct libevdev *dev, const struct input_event *e)
>  			break;
>  	}
>  
> -	dev->last_event_time = e->time;
> +	dev->last_event_time.tv_sec = e->input_event_sec;
> +	dev->last_event_time.tv_usec = e->input_event_usec;
>  
>  	return rc;
>  }
> diff --git a/test/test-libevdev-init.c b/test/test-libevdev-init.c
> index f673a58..feba27f 100644
> --- a/test/test-libevdev-init.c
> +++ b/test/test-libevdev-init.c
> @@ -575,19 +575,19 @@ START_TEST(test_clock_id_events)
>  	ck_assert_int_eq(ev1.code, ev2.code);
>  	ck_assert_int_eq(ev1.value, ev2.value);
>  
> -	t1 = ev1.time.tv_sec * 1000000LL + ev1.time.tv_usec;
> -	t2 = ev2.time.tv_sec * 1000000LL + ev2.time.tv_usec;
> +	t1 = ev1.input_event_sec * 1000000LL + ev1.input_event_usec;
> +	t2 = ev2.input_event_sec * 1000000LL + ev2.input_event_usec;
>  	ck_assert_int_ne(t1, t2);
>  
> -	ck_assert_int_ge(ev1.time.tv_sec, t1_real.tv_sec);
> -	ck_assert_int_ge(ev1.time.tv_usec, t1_real.tv_nsec/1000);
> -	ck_assert_int_le(ev1.time.tv_sec, t2_real.tv_sec);
> -	ck_assert_int_le(ev1.time.tv_usec, t2_real.tv_nsec/1000);
> +	ck_assert_int_ge(ev1.input_event_sec, t1_real.tv_sec);
> +	ck_assert_int_ge(ev1.input_event_usec, t1_real.tv_nsec/1000);
> +	ck_assert_int_le(ev1.input_event_sec, t2_real.tv_sec);
> +	ck_assert_int_le(ev1.input_event_usec, t2_real.tv_nsec/1000);
>  
> -	ck_assert_int_ge(ev2.time.tv_sec, t1_mono.tv_sec);
> -	ck_assert_int_ge(ev2.time.tv_usec, t1_mono.tv_nsec/1000);
> -	ck_assert_int_le(ev2.time.tv_sec, t2_mono.tv_sec);
> -	ck_assert_int_le(ev2.time.tv_usec, t2_mono.tv_nsec/1000);
> +	ck_assert_int_ge(ev2.input_event_sec, t1_mono.tv_sec);
> +	ck_assert_int_ge(ev2.input_event_usec, t1_mono.tv_nsec/1000);
> +	ck_assert_int_le(ev2.input_event_sec, t2_mono.tv_sec);
> +	ck_assert_int_le(ev2.input_event_usec, t2_mono.tv_nsec/1000);
>  
>  	uinput_device_free(uidev);
>  	libevdev_free(dev);
> diff --git a/tools/libevdev-events.c b/tools/libevdev-events.c
> index 3ce23f1..dfd841f 100644
> --- a/tools/libevdev-events.c
> +++ b/tools/libevdev-events.c
> @@ -112,13 +112,13 @@ print_event(struct input_event *ev)
>  {
>  	if (ev->type == EV_SYN)
>  		printf("Event: time %ld.%06ld, ++++++++++++++++++++ %s +++++++++++++++\n",
> -				ev->time.tv_sec,
> -				ev->time.tv_usec,
> +				ev->input_event_sec,
> +				ev->input_event_usec,
>  				libevdev_event_type_get_name(ev->type));
>  	else
>  		printf("Event: time %ld.%06ld, type %d (%s), code %d (%s), value %d\n",
> -			ev->time.tv_sec,
> -			ev->time.tv_usec,
> +			ev->input_event_sec,
> +			ev->input_event_usec,
>  			ev->type,
>  			libevdev_event_type_get_name(ev->type),
>  			ev->code,
> diff --git a/tools/mouse-dpi-tool.c b/tools/mouse-dpi-tool.c
> index b472ad0..da44124 100644
> --- a/tools/mouse-dpi-tool.c
> +++ b/tools/mouse-dpi-tool.c
> @@ -61,12 +61,6 @@ usage(void) {
>  	return 1;
>  }
>  
> -static inline uint64_t
> -tv2us(const struct timeval *tv)
> -{
> -	return tv->tv_sec * 1000000 + tv->tv_usec;
> -}
> -
>  static inline double
>  get_frequency(uint64_t last, uint64_t current)
>  {
> @@ -119,7 +113,7 @@ handle_event(struct measurements *m, const struct input_event *ev)
>  		const int idle_reset = 3000000; /* us */
>  		uint64_t last_us = m->us;
>  
> -		m->us = tv2us(&ev->time);
> +		m->us = ev->input_event_sec * 1000000 + ev->input_event_usec;
>  
>  		/* reset after pause */
>  		if (last_us + idle_reset < m->us) {
> -- 
> 2.14.1
> 
> _______________________________________________
> Input-tools mailing list
> Input-tools at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/input-tools
> 


More information about the Input-tools mailing list