From e2a45dad38d8fe7e1f6a320bda5230467d74b304 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 6 Feb 2023 11:38:45 +1000 Subject: [PATCH] eis: switch to a goto out approach Makes the code a bit easier to follow --- src/libeis-device.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/libeis-device.c b/src/libeis-device.c index ef3ebe9..9a46c61 100644 --- a/src/libeis-device.c +++ b/src/libeis-device.c @@ -384,26 +384,42 @@ eis_device_add(struct eis_device *device) eis_client_register_object(client, &device->proto_object); eis_seat_event_device(seat, device->proto_object.id, device->proto_object.version); int rc = eis_device_event_name(device, device->name); - if (rc == 0) - rc = eis_device_event_capabilities(device, device->capabilities); - if (rc == 0) - rc = eis_device_event_type(device, device->type); - if (rc == 0 && device->type == EIS_DEVICE_TYPE_PHYSICAL) + if (rc < 0) + goto out; + + rc = eis_device_event_capabilities(device, device->capabilities); + if (rc < 0) + goto out; + + rc = eis_device_event_type(device, device->type); + if (rc < 0) + goto out; + + if (device->type == EIS_DEVICE_TYPE_PHYSICAL) { rc = eis_device_event_dimensions(device, device->width, device->height); - if (rc == 0 &&device->type == EIS_DEVICE_TYPE_VIRTUAL) { + if (rc < 0) + goto out; + } + if (device->type == EIS_DEVICE_TYPE_VIRTUAL) { struct eis_region *r; list_for_each(r, &device->regions, link) { rc = eis_device_event_region(device, r->x, r->y, r->width, r->height, r->physical_scale); - if (rc != 0) - break; + if (rc < 0) + goto out; } } - if (rc >= 0 && device->keymap) - rc = eis_device_event_keymap(device, device->keymap->type, device->keymap->size, device->keymap->fd); - if (rc == 0) - eis_device_event_done(device); + if (device->keymap) { + rc = eis_device_event_keymap(device, device->keymap->type, device->keymap->size, device->keymap->fd); + if (rc < 0) + goto out; + } + rc = eis_device_event_done(device); + if (rc < 0) + goto out; +out: /* FIXME: check rc */ + return; } _public_ void