diff options
author | Rosen Penev <rosenp@gmail.com> | 2020-08-27 00:42:20 -0700 |
---|---|---|
committer | Rosen Penev <rosenp@gmail.com> | 2020-08-27 00:42:20 -0700 |
commit | fb6a84a52a7b31eb33df99564e4ba239855a0241 (patch) | |
tree | 0df255e529279c93be44ad2598d45aa5c4b6c74c | |
parent | a40e014eca8e27aecc1fd9e10440444687c0a3e9 (diff) | |
download | libevdev-fb6a84a52a7b31eb33df99564e4ba239855a0241.tar.gz |
[clang-tidy] do not use else after return
Found with readability-else-after-return
Signed-off-by: Rosen Penev <rosenp@gmail.com>
-rw-r--r-- | libevdev/libevdev-uinput.c | 21 | ||||
-rw-r--r-- | libevdev/libevdev.c | 62 | ||||
-rw-r--r-- | tools/mouse-dpi-tool.c | 13 | ||||
-rw-r--r-- | tools/touchpad-edge-detector.c | 15 |
4 files changed, 67 insertions, 44 deletions
diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c index 12c8a49..d781fe6 100644 --- a/libevdev/libevdev-uinput.c +++ b/libevdev/libevdev-uinput.c @@ -298,18 +298,19 @@ fetch_syspath_and_devnode(struct libevdev_uinput *uinput_dev) /* FIXME: could descend into bit comparison here */ log_info(NULL, "multiple identical devices found. syspath is unreliable\n"); break; - } else { - rc = snprintf(buf, sizeof(buf), "%s%s", - SYS_INPUT_DIR, - namelist[i]->d_name); - if (rc < 0 || (size_t)rc >= sizeof(buf)) { - log_error(NULL, "Invalid syspath, syspath is unreliable\n"); - break; - } + } + + rc = snprintf(buf, sizeof(buf), "%s%s", + SYS_INPUT_DIR, + namelist[i]->d_name); - uinput_dev->syspath = strdup(buf); - uinput_dev->devnode = fetch_device_node(buf); + if (rc < 0 || (size_t)rc >= sizeof(buf)) { + log_error(NULL, "Invalid syspath, syspath is unreliable\n"); + break; } + + uinput_dev->syspath = strdup(buf); + uinput_dev->devnode = fetch_device_node(buf); } } diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c index 4c6ef04..7dea906 100644 --- a/libevdev/libevdev.c +++ b/libevdev/libevdev.c @@ -317,8 +317,7 @@ _libevdev_log_priority(const struct libevdev *dev) { if (dev && dev->log.device_handler) return dev->log.priority; - else - return libevdev_get_log_priority(); + return libevdev_get_log_priority(); } LIBEVDEV_EXPORT int @@ -398,7 +397,9 @@ libevdev_set_fd(struct libevdev* dev, int fd) if (dev->initialized) { log_bug(dev, "device already initialized.\n"); return -EBADF; - } else if (fd < 0) { + } + + if (fd < 0) { return -EBADF; } @@ -870,11 +871,13 @@ read_more_events(struct libevdev *dev) next = queue_next_element(dev); len = read(dev->fd, next, free_elem * sizeof(struct input_event)); - if (len < 0) { + if (len < 0) return -errno; - } else if (len > 0 && len % sizeof(struct input_event) != 0) { + + if (len > 0 && len % sizeof(struct input_event) != 0) return -EINVAL; - } else if (len > 0) { + + if (len > 0) { int nev = len/sizeof(struct input_event); queue_set_num_elements(dev, queue_num_elements(dev) + nev); } @@ -997,10 +1000,11 @@ update_mt_state(struct libevdev *dev, const struct input_event *e) } return 0; - } else if (dev->current_slot == -1) { - return 1; } + if (dev->current_slot == -1) + return 1; + *slot_value(dev, dev->current_slot, e->code) = e->value; return 0; @@ -1104,7 +1108,9 @@ sanitize_event(const struct libevdev *dev, N to -1 or from -1 to N. Never from -1 to -1, or N to M. Very unlikely to ever happen from a real device. */ - } else if (unlikely(sync_state == SYNC_NONE && + } + + if (unlikely(sync_state == SYNC_NONE && dev->num_slots > -1 && libevdev_event_is_code(ev, EV_ABS, ABS_MT_TRACKING_ID) && ((ev->value == -1 && @@ -1132,10 +1138,11 @@ libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event if (!dev->initialized) { log_bug(dev, "device not initialized. call libevdev_set_fd() first\n"); return -EBADF; - } else if (dev->fd < 0) { - return -EBADF; } + if (dev->fd < 0) + return -EBADF; + if ((flags & valid_flags) == 0) { log_bug(dev, "invalid flags %#x.\n", flags); return -EINVAL; @@ -1224,10 +1231,11 @@ libevdev_has_event_pending(struct libevdev *dev) if (!dev->initialized) { log_bug(dev, "device not initialized. call libevdev_set_fd() first\n"); return -EBADF; - } else if (dev->fd < 0) { - return -EBADF; } + if (dev->fd < 0) + return -EBADF; + if (queue_num_elements(dev) != 0) return 1; @@ -1406,9 +1414,9 @@ libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, unsign libevdev_has_event_code(dev, type, code)) { *value = libevdev_get_event_value(dev, type, code); return 1; - } else { - return 0; } + + return 0; } LIBEVDEV_EXPORT int @@ -1458,9 +1466,9 @@ libevdev_fetch_slot_value(const struct libevdev *dev, unsigned int slot, unsigne slot < (unsigned int)dev->num_slots) { *value = libevdev_get_slot_value(dev, slot, code); return 1; - } else { - return 0; } + + return 0; } LIBEVDEV_EXPORT int @@ -1647,10 +1655,11 @@ libevdev_kernel_set_abs_info(struct libevdev *dev, unsigned int code, const stru if (!dev->initialized) { log_bug(dev, "device not initialized. call libevdev_set_fd() first\n"); return -EBADF; - } else if (dev->fd < 0) { - return -EBADF; } + if (dev->fd < 0) + return -EBADF; + if (code > ABS_MAX) return -EINVAL; @@ -1671,10 +1680,11 @@ libevdev_grab(struct libevdev *dev, enum libevdev_grab_mode grab) if (!dev->initialized) { log_bug(dev, "device not initialized. call libevdev_set_fd() first\n"); return -EBADF; - } else if (dev->fd < 0) { - return -EBADF; } + if (dev->fd < 0) + return -EBADF; + if (grab != LIBEVDEV_GRAB && grab != LIBEVDEV_UNGRAB) { log_bug(dev, "invalid grab parameter %#x\n", grab); return -EINVAL; @@ -1800,10 +1810,11 @@ libevdev_kernel_set_led_values(struct libevdev *dev, ...) if (!dev->initialized) { log_bug(dev, "device not initialized. call libevdev_set_fd() first\n"); return -EBADF; - } else if (dev->fd < 0) { - return -EBADF; } + if (dev->fd < 0) + return -EBADF; + memset(ev, 0, sizeof(ev)); va_start(args, dev); @@ -1857,9 +1868,10 @@ libevdev_set_clock_id(struct libevdev *dev, int clockid) if (!dev->initialized) { log_bug(dev, "device not initialized. call libevdev_set_fd() first\n"); return -EBADF; - } else if (dev->fd < 0) { - return -EBADF; } + if (dev->fd < 0) + return -EBADF; + return ioctl(dev->fd, EVIOCSCLOCKID, &clockid) ? -errno : 0; } diff --git a/tools/mouse-dpi-tool.c b/tools/mouse-dpi-tool.c index 30f67b8..1088754 100644 --- a/tools/mouse-dpi-tool.c +++ b/tools/mouse-dpi-tool.c @@ -129,7 +129,9 @@ handle_event(struct measurements *m, const struct input_event *ev) } return 0; - } else if (ev->type != EV_REL) + } + + if (ev->type != EV_REL) return 0; switch(ev->code) { @@ -168,12 +170,15 @@ mainloop(struct libevdev *dev, struct measurements *m) { if (rc == LIBEVDEV_READ_STATUS_SYNC) { fprintf(stderr, "Error: cannot keep up\n"); return 1; - } else if (rc != -EAGAIN && rc < 0) { + } + + if (rc != -EAGAIN && rc < 0) { fprintf(stderr, "Error: %s\n", strerror(-rc)); return 1; - } else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) { - handle_event(m, &ev); } + + if (rc == LIBEVDEV_READ_STATUS_SUCCESS) + handle_event(m, &ev); } while (rc != -EAGAIN); } diff --git a/tools/touchpad-edge-detector.c b/tools/touchpad-edge-detector.c index 9c64bc7..bf20b25 100644 --- a/tools/touchpad-edge-detector.c +++ b/tools/touchpad-edge-detector.c @@ -84,9 +84,10 @@ print_current_values(const struct dimensions *d) static int handle_event(struct dimensions *d, const struct input_event *ev) { - if (ev->type == EV_SYN) { + if (ev->type == EV_SYN) return print_current_values(d); - } else if (ev->type != EV_ABS) + + if (ev->type != EV_ABS) return 0; switch(ev->code) { @@ -132,12 +133,16 @@ mainloop(struct libevdev *dev, struct dimensions *dim) { if (rc == LIBEVDEV_READ_STATUS_SYNC) { fprintf(stderr, "Error: cannot keep up\n"); return 1; - } else if (rc != -EAGAIN && rc < 0) { + } + + if (rc != -EAGAIN && rc < 0) { fprintf(stderr, "Error: %s\n", strerror(-rc)); return 1; - } else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) { - handle_event(dim, &ev); + } + + if (rc == LIBEVDEV_READ_STATUS_SUCCESS) + handle_event(dim, &ev); } while (rc != -EAGAIN); } |