mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-25 01:10:10 +01:00
[clang-tidy] do not use else after return
Found with readability-else-after-return Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
a40e014eca
commit
fb6a84a52a
4 changed files with 68 additions and 45 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
uinput_dev->syspath = strdup(buf);
|
||||
uinput_dev->devnode = fetch_device_node(buf);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uinput_dev->syspath = strdup(buf);
|
||||
uinput_dev->devnode = fetch_device_node(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue