[PATCH libinput] evdev: replace null sentinel with ARRAY_SIZE

Peter Hutterer peter.hutterer at who-t.net
Thu May 11 00:39:13 UTC 2017


On Wed, May 10, 2017 at 11:13:07AM +0100, Eric Engestrom wrote:
> Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
> ---
>  src/evdev.c | 17 +++++++----------
>  1 file changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/src/evdev.c b/src/evdev.c
> index a2be6fc..7895644 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -50,6 +50,8 @@
>  #define DEFAULT_WHEEL_CLICK_ANGLE 15
>  #define DEFAULT_BUTTON_SCROLL_TIMEOUT ms2us(200)
>  
> +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a)[0])

We already have ARRAY_LENGTH, I fixed this up accordingly and squashed my
{ 0, 0 } patch into this one, no point having to patches here. Thanks!

Cheers,
   Peter

> +
>  enum evdev_key_type {
>  	EVDEV_KEY_TYPE_NONE,
>  	EVDEV_KEY_TYPE_KEY,
> @@ -90,9 +92,6 @@ static const struct evdev_udev_tag_match evdev_udev_tag_matches[] = {
>  	{"ID_INPUT_POINTINGSTICK",	EVDEV_UDEV_TAG_POINTINGSTICK},
>  	{"ID_INPUT_TRACKBALL",		EVDEV_UDEV_TAG_TRACKBALL},
>  	{"ID_INPUT_SWITCH",		EVDEV_UDEV_TAG_SWITCH},
> -
> -	/* sentinel value */
> -	{0, 0},
>  };
>  
>  static inline bool
> @@ -2373,18 +2372,16 @@ evdev_device_get_udev_tags(struct evdev_device *device,
>  			   struct udev_device *udev_device)
>  {
>  	enum evdev_device_udev_tags tags = 0;
> -	const struct evdev_udev_tag_match *match;
>  	int i;
>  
>  	for (i = 0; i < 2 && udev_device; i++) {
> -		match = evdev_udev_tag_matches;
> -		while (match->name) {
> +		unsigned j;
> +		for (j = 0; j < ARRAY_SIZE(evdev_udev_tag_matches); j++) {
> +			const struct evdev_udev_tag_match match = evdev_udev_tag_matches[j];
>  			if (parse_udev_flag(device,
>  					    udev_device,
> -					    match->name))
> -				tags |= match->tag;
> -
> -			match++;
> +					    match.name))
> +				tags |= match.tag;
>  		}
>  		udev_device = udev_device_get_parent(udev_device);
>  	}
> -- 
> Cheers,
>   Eric
> 


More information about the wayland-devel mailing list