[PATCH 9/9] evdev: simplify error path for device create

Tiago Vignatti tiago.vignatti at intel.com
Mon Oct 24 07:42:22 PDT 2011


Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
 compositor/evdev.c |   31 +++++++++++++------------------
 1 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/compositor/evdev.c b/compositor/evdev.c
index 18ebe04..7f4b57b 100644
--- a/compositor/evdev.c
+++ b/compositor/evdev.c
@@ -490,33 +490,28 @@ evdev_input_device_create(struct evdev_input *master,
 	device->is_touchpad = 0;
 
 	device->fd = open(path, O_RDONLY);
-	if (device->fd < 0) {
-		free(device->devnode);
-		free(device);
-		fprintf(stderr, "couldn't create pointer for %s: %m\n", path);
-		return NULL;
-	}
+	if (device->fd < 0)
+		goto err0;
 
-	if (evdev_configure_device(device) == -1) {
-		close(device->fd);
-		free(device->devnode);
-		free(device);
-		return NULL;
-	}
+	if (evdev_configure_device(device) == -1)
+		goto err1;
 
 	loop = wl_display_get_event_loop(display);
 	device->source = wl_event_loop_add_fd(loop, device->fd,
 					      WL_EVENT_READABLE,
 					      evdev_input_device_data, device);
-	if (device->source == NULL) {
-		close(device->fd);
-		free(device->devnode);
-		free(device);
-		return NULL;
-	}
+	if (device->source == NULL)
+		goto err1;
 
 	wl_list_insert(master->devices_list.prev, &device->link);
 	return device;
+
+err1:
+	close(device->fd);
+err0:
+	free(device->devnode);
+	free(device);
+	return NULL;
 }
 
 static void
-- 
1.7.5.4



More information about the wayland-devel mailing list