[PATCH libinput 1/4] evdev: add helper function to parse a udev flag

Peter Hutterer peter.hutterer at who-t.net
Tue Nov 29 02:28:22 UTC 2016


Only allow values of 0 and 1 for udev flags. Not that I'm aware of anyone
using anything else (i.e. his shouldn't break anything) but it's best to be as
restrictive as possible here.

Bonus effect: it's now possible to unset LIBINPUT_MODEL_* tags as well,
previously any value (including 0) was counted as "yes".

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index afb5e34..500a0f8 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -93,6 +93,28 @@ static const struct evdev_udev_tag_match evdev_udev_tag_matches[] = {
 	{ 0 },
 };
 
+static inline bool
+parse_udev_flag(struct evdev_device *device,
+		struct udev_device *udev_device,
+		const char *property)
+{
+	const char *val;
+
+	val = udev_device_get_property_value(udev_device, property);
+	if (!val)
+		return false;
+
+	if (streq(val, "1"))
+		return true;
+	if (!streq(val, "0"))
+		log_error(evdev_libinput_context(device),
+			  "%s: property %s has invalid value '%s'\n",
+			  evdev_device_get_sysname(device),
+			  property,
+			  val);
+	return false;
+}
+
 static void
 hw_set_key_down(struct fallback_dispatch *dispatch, int code, int pressed)
 {
@@ -1026,8 +1048,7 @@ evdev_tag_trackpoint(struct evdev_device *device,
 {
 	if (libevdev_has_property(device->evdev,
 				  INPUT_PROP_POINTING_STICK) ||
-	    udev_device_get_property_value(udev_device,
-					   "ID_INPUT_POINTINGSTICK"))
+	    parse_udev_flag(device, udev_device, "ID_INPUT_POINTINGSTICK"))
 		device->tags |= EVDEV_TAG_TRACKPOINT;
 }
 
@@ -2192,12 +2213,11 @@ evdev_read_model_flags(struct evdev_device *device)
 	};
 	const struct model_map *m = model_map;
 	uint32_t model_flags = 0;
-	const char *val;
 
 	while (m->property) {
-		val = udev_device_get_property_value(device->udev_device,
-						     m->property);
-		if (val && !streq(val, "0")) {
+		if (parse_udev_flag(device,
+				    device->udev_device,
+				    m->property)) {
 			log_debug(evdev_libinput_context(device),
 				  "%s: tagged as %s\n",
 				  evdev_device_get_sysname(device),
@@ -2293,7 +2313,6 @@ static enum evdev_device_udev_tags
 evdev_device_get_udev_tags(struct evdev_device *device,
 			   struct udev_device *udev_device)
 {
-	const char *prop;
 	enum evdev_device_udev_tags tags = 0;
 	const struct evdev_udev_tag_match *match;
 	int i;
@@ -2301,10 +2320,9 @@ evdev_device_get_udev_tags(struct evdev_device *device,
 	for (i = 0; i < 2 && udev_device; i++) {
 		match = evdev_udev_tag_matches;
 		while (match->name) {
-			prop = udev_device_get_property_value(
-						      udev_device,
-						      match->name);
-			if (prop)
+			if (parse_udev_flag(device,
+					    udev_device,
+					    match->name))
 				tags |= match->tag;
 
 			match++;
-- 
2.9.3



More information about the wayland-devel mailing list