From e94797108b98045fcdbdebe2237f9d98b951fa96 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Sun, 13 Oct 2019 17:13:52 +0200
Subject: [PATCH 60/76] evdev: remove additional indentation level for switch
case labels
And while we are here, factor out evdev_write_ioctl_mpers call
out of the switch statement.
* evdev.c (bit_ioctl, evdev_read_ioctl, evdev_ioctl): Remove
one indentation level inside the switch statements.
(evedev_write_ioctl): Remove one indentation level inside the switch
statement; move default branch out of the switch statement.
Conflicts:
evdev.c
---
evdev.c | 231 +++++++++++++++++++++++++++++-----------------------------
evdev_mpers.c | 86 +++++++++++-----------
2 files changed, 158 insertions(+), 159 deletions(-)
diff --git a/evdev.c b/evdev.c
index e402d26..b9ac666 100644
--- a/evdev.c
+++ b/evdev.c
@@ -238,48 +238,48 @@ bit_ioctl(struct tcb *const tcp, const unsigned int ev_nr,
const kernel_ulong_t arg)
{
switch (ev_nr) {
- case 0:
- return decode_bitset(tcp, arg, evdev_ev,
- EV_MAX, "EV_???", XT_SORTED);
- case EV_KEY:
- return decode_bitset(tcp, arg, evdev_keycode,
- KEY_MAX, "KEY_???", XT_INDEXED);
- case EV_REL:
- return decode_bitset(tcp, arg, evdev_relative_axes,
- REL_MAX, "REL_???", XT_INDEXED);
- case EV_ABS:
- return decode_bitset(tcp, arg, evdev_abs,
- ABS_MAX, "ABS_???", XT_INDEXED);
- case EV_MSC:
- return decode_bitset(tcp, arg, evdev_misc,
- MSC_MAX, "MSC_???", XT_INDEXED);
- case EV_SW:
- return decode_bitset(tcp, arg, evdev_switch,
- SW_MAX, "SW_???", XT_INDEXED);
- case EV_LED:
- return decode_bitset(tcp, arg, evdev_leds,
- LED_MAX, "LED_???", XT_INDEXED);
- case EV_SND:
- return decode_bitset(tcp, arg, evdev_snd,
- SND_MAX, "SND_???", XT_INDEXED);
- case EV_REP:
- return decode_bitset(tcp, arg, evdev_autorepeat,
- REP_MAX, "REP_???", XT_INDEXED);
- case EV_FF:
- return decode_bitset(tcp, arg, evdev_ff_types,
- FF_MAX, "FF_???", XT_SORTED);
- case EV_PWR:
- tprints(", ");
- printnum_int(tcp, arg, "%d");
- return RVAL_IOCTL_DECODED;
- case EV_FF_STATUS:
- return decode_bitset(tcp, arg, evdev_ff_status,
- FF_STATUS_MAX, "FF_STATUS_???",
- XT_INDEXED);
- default:
- tprints(", ");
- printaddr(arg);
- return RVAL_IOCTL_DECODED;
+ case 0:
+ return decode_bitset(tcp, arg, evdev_ev,
+ EV_MAX, "EV_???", XT_SORTED);
+ case EV_KEY:
+ return decode_bitset(tcp, arg, evdev_keycode,
+ KEY_MAX, "KEY_???", XT_INDEXED);
+ case EV_REL:
+ return decode_bitset(tcp, arg, evdev_relative_axes,
+ REL_MAX, "REL_???", XT_INDEXED);
+ case EV_ABS:
+ return decode_bitset(tcp, arg, evdev_abs,
+ ABS_MAX, "ABS_???", XT_INDEXED);
+ case EV_MSC:
+ return decode_bitset(tcp, arg, evdev_misc,
+ MSC_MAX, "MSC_???", XT_INDEXED);
+ case EV_SW:
+ return decode_bitset(tcp, arg, evdev_switch,
+ SW_MAX, "SW_???", XT_INDEXED);
+ case EV_LED:
+ return decode_bitset(tcp, arg, evdev_leds,
+ LED_MAX, "LED_???", XT_INDEXED);
+ case EV_SND:
+ return decode_bitset(tcp, arg, evdev_snd,
+ SND_MAX, "SND_???", XT_INDEXED);
+ case EV_REP:
+ return decode_bitset(tcp, arg, evdev_autorepeat,
+ REP_MAX, "REP_???", XT_INDEXED);
+ case EV_FF:
+ return decode_bitset(tcp, arg, evdev_ff_types,
+ FF_MAX, "FF_???", XT_SORTED);
+ case EV_PWR:
+ tprints(", ");
+ printnum_int(tcp, arg, "%d");
+ return RVAL_IOCTL_DECODED;
+ case EV_FF_STATUS:
+ return decode_bitset(tcp, arg, evdev_ff_status,
+ FF_STATUS_MAX, "FF_STATUS_???",
+ XT_INDEXED);
+ default:
+ tprints(", ");
+ printaddr(arg);
+ return RVAL_IOCTL_DECODED;
}
}
@@ -289,63 +289,63 @@ evdev_read_ioctl(struct tcb *const tcp, const unsigned int code,
{
/* fixed-number fixed-length commands */
switch (code) {
- case EVIOCGVERSION:
- tprints(", ");
- printnum_int(tcp, arg, "%#x");
- return RVAL_IOCTL_DECODED;
- case EVIOCGEFFECTS:
- tprints(", ");
- printnum_int(tcp, arg, "%u");
- return RVAL_IOCTL_DECODED;
- case EVIOCGID:
- return getid_ioctl(tcp, arg);
+ case EVIOCGVERSION:
+ tprints(", ");
+ printnum_int(tcp, arg, "%#x");
+ return RVAL_IOCTL_DECODED;
+ case EVIOCGEFFECTS:
+ tprints(", ");
+ printnum_int(tcp, arg, "%u");
+ return RVAL_IOCTL_DECODED;
+ case EVIOCGID:
+ return getid_ioctl(tcp, arg);
# ifdef EVIOCGREP
- case EVIOCGREP:
- return repeat_ioctl(tcp, arg);
+ case EVIOCGREP:
+ return repeat_ioctl(tcp, arg);
# endif
- case EVIOCGKEYCODE:
- return keycode_ioctl(tcp, arg);
+ case EVIOCGKEYCODE:
+ return keycode_ioctl(tcp, arg);
# ifdef EVIOCGKEYCODE_V2
- case EVIOCGKEYCODE_V2:
- return keycode_V2_ioctl(tcp, arg);
+ case EVIOCGKEYCODE_V2:
+ return keycode_V2_ioctl(tcp, arg);
# endif
}
/* fixed-number variable-length commands */
switch (_IOC_NR(code)) {
# ifdef EVIOCGMTSLOTS
- case _IOC_NR(EVIOCGMTSLOTS(0)):
- return mtslots_ioctl(tcp, code, arg);
+ case _IOC_NR(EVIOCGMTSLOTS(0)):
+ return mtslots_ioctl(tcp, code, arg);
# endif
- case _IOC_NR(EVIOCGNAME(0)):
- case _IOC_NR(EVIOCGPHYS(0)):
- case _IOC_NR(EVIOCGUNIQ(0)):
- tprints(", ");
- if (syserror(tcp))
- printaddr(arg);
- else
- printstrn(tcp, arg, tcp->u_rval);
- return RVAL_IOCTL_DECODED;
+ case _IOC_NR(EVIOCGNAME(0)):
+ case _IOC_NR(EVIOCGPHYS(0)):
+ case _IOC_NR(EVIOCGUNIQ(0)):
+ tprints(", ");
+ if (syserror(tcp))
+ printaddr(arg);
+ else
+ printstrn(tcp, arg, tcp->u_rval);
+ return RVAL_IOCTL_DECODED;
# ifdef EVIOCGPROP
- case _IOC_NR(EVIOCGPROP(0)):
- return decode_bitset(tcp, arg, evdev_prop,
- INPUT_PROP_MAX, "PROP_???",
- XT_INDEXED);
+ case _IOC_NR(EVIOCGPROP(0)):
+ return decode_bitset(tcp, arg, evdev_prop,
+ INPUT_PROP_MAX, "PROP_???",
+ XT_INDEXED);
# endif
- case _IOC_NR(EVIOCGSND(0)):
- return decode_bitset(tcp, arg, evdev_snd,
- SND_MAX, "SND_???", XT_INDEXED);
+ case _IOC_NR(EVIOCGSND(0)):
+ return decode_bitset(tcp, arg, evdev_snd,
+ SND_MAX, "SND_???", XT_INDEXED);
# ifdef EVIOCGSW
- case _IOC_NR(EVIOCGSW(0)):
- return decode_bitset(tcp, arg, evdev_switch,
- SW_MAX, "SW_???", XT_INDEXED);
+ case _IOC_NR(EVIOCGSW(0)):
+ return decode_bitset(tcp, arg, evdev_switch,
+ SW_MAX, "SW_???", XT_INDEXED);
# endif
- case _IOC_NR(EVIOCGKEY(0)):
- return decode_bitset(tcp, arg, evdev_keycode,
- KEY_MAX, "KEY_???", XT_INDEXED);
- case _IOC_NR(EVIOCGLED(0)):
- return decode_bitset(tcp, arg, evdev_leds,
- LED_MAX, "LED_???", XT_INDEXED);
+ case _IOC_NR(EVIOCGKEY(0)):
+ return decode_bitset(tcp, arg, evdev_keycode,
+ KEY_MAX, "KEY_???", XT_INDEXED);
+ case _IOC_NR(EVIOCGLED(0)):
+ return decode_bitset(tcp, arg, evdev_leds,
+ LED_MAX, "LED_???", XT_INDEXED);
}
/* multi-number fixed-length commands */
@@ -366,38 +366,37 @@ evdev_write_ioctl(struct tcb *const tcp, const unsigned int code,
/* fixed-number fixed-length commands */
switch (code) {
# ifdef EVIOCSREP
- case EVIOCSREP:
- return repeat_ioctl(tcp, arg);
+ case EVIOCSREP:
+ return repeat_ioctl(tcp, arg);
# endif
- case EVIOCSKEYCODE:
- return keycode_ioctl(tcp, arg);
+ case EVIOCSKEYCODE:
+ return keycode_ioctl(tcp, arg);
# ifdef EVIOCSKEYCODE_V2
- case EVIOCSKEYCODE_V2:
- return keycode_V2_ioctl(tcp, arg);
+ case EVIOCSKEYCODE_V2:
+ return keycode_V2_ioctl(tcp, arg);
# endif
- case EVIOCRMFF:
- tprintf(", %d", (int) arg);
- return RVAL_IOCTL_DECODED;
- case EVIOCGRAB:
+ case EVIOCRMFF:
+ tprintf(", %d", (int) arg);
+ return RVAL_IOCTL_DECODED;
+ case EVIOCGRAB:
# ifdef EVIOCREVOKE
- case EVIOCREVOKE:
+ case EVIOCREVOKE:
# endif
- tprintf(", %" PRI_klu, arg);
- return RVAL_IOCTL_DECODED;
+ tprintf(", %" PRI_klu, arg);
+ return RVAL_IOCTL_DECODED;
# ifdef EVIOCSCLOCKID
- case EVIOCSCLOCKID:
- tprints(", ");
- printnum_int(tcp, arg, "%u");
- return RVAL_IOCTL_DECODED;
+ case EVIOCSCLOCKID:
+ tprints(", ");
+ printnum_int(tcp, arg, "%u");
+ return RVAL_IOCTL_DECODED;
# endif
- default: {
- int rc = evdev_write_ioctl_mpers(tcp, code, arg);
-
- if (rc != RVAL_DECODED)
- return rc;
- }
}
+ int rc = evdev_write_ioctl_mpers(tcp, code, arg);
+
+ if (rc != RVAL_DECODED)
+ return rc;
+
/* multi-number fixed-length commands */
if ((_IOC_NR(code) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0)))
return abs_ioctl(tcp, arg);
@@ -416,14 +415,14 @@ evdev_ioctl(struct tcb *const tcp,
const unsigned int code, const kernel_ulong_t arg)
{
switch (_IOC_DIR(code)) {
- case _IOC_READ:
- if (entering(tcp))
- return 0;
- return evdev_read_ioctl(tcp, code, arg);
- case _IOC_WRITE:
- return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED;
- default:
- return RVAL_DECODED;
+ case _IOC_READ:
+ if (entering(tcp))
+ return 0;
+ return evdev_read_ioctl(tcp, code, arg);
+ case _IOC_WRITE:
+ return evdev_write_ioctl(tcp, code, arg) | RVAL_DECODED;
+ default:
+ return RVAL_DECODED;
}
}
diff --git a/evdev_mpers.c b/evdev_mpers.c
index ff99544..ebf9658 100644
--- a/evdev_mpers.c
+++ b/evdev_mpers.c
@@ -71,45 +71,45 @@ ff_effect_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
ffe.replay.delay);
switch (ffe.type) {
- case FF_CONSTANT:
- tprintf(", constant={level=%" PRId16,
- ffe.u.constant.level);
- decode_envelope(&ffe.u.constant.envelope);
- tprints("}");
- break;
- case FF_RAMP:
- tprintf(", ramp={start_level=%" PRId16
- ", end_level=%" PRId16,
- ffe.u.ramp.start_level,
- ffe.u.ramp.end_level);
- decode_envelope(&ffe.u.ramp.envelope);
- tprints("}");
- break;
- case FF_PERIODIC:
- tprintf(", periodic={waveform=%" PRIu16
- ", period=%" PRIu16
- ", magnitude=%" PRId16
- ", offset=%" PRId16
- ", phase=%" PRIu16,
- ffe.u.periodic.waveform,
- ffe.u.periodic.period,
- ffe.u.periodic.magnitude,
- ffe.u.periodic.offset,
- ffe.u.periodic.phase);
- decode_envelope(&ffe.u.periodic.envelope);
- tprintf(", custom_len=%u, custom_data=",
- ffe.u.periodic.custom_len);
- printaddr(ptr_to_kulong(ffe.u.periodic.custom_data));
- tprints("}");
- break;
- case FF_RUMBLE:
- tprintf(", rumble={strong_magnitude=%" PRIu16
- ", weak_magnitude=%" PRIu16 "}",
- ffe.u.rumble.strong_magnitude,
- ffe.u.rumble.weak_magnitude);
- break;
- default:
- break;
+ case FF_CONSTANT:
+ tprintf(", constant={level=%" PRId16,
+ ffe.u.constant.level);
+ decode_envelope(&ffe.u.constant.envelope);
+ tprints("}");
+ break;
+ case FF_RAMP:
+ tprintf(", ramp={start_level=%" PRId16
+ ", end_level=%" PRId16,
+ ffe.u.ramp.start_level,
+ ffe.u.ramp.end_level);
+ decode_envelope(&ffe.u.ramp.envelope);
+ tprints("}");
+ break;
+ case FF_PERIODIC:
+ tprintf(", periodic={waveform=%" PRIu16
+ ", period=%" PRIu16
+ ", magnitude=%" PRId16
+ ", offset=%" PRId16
+ ", phase=%" PRIu16,
+ ffe.u.periodic.waveform,
+ ffe.u.periodic.period,
+ ffe.u.periodic.magnitude,
+ ffe.u.periodic.offset,
+ ffe.u.periodic.phase);
+ decode_envelope(&ffe.u.periodic.envelope);
+ tprintf(", custom_len=%u, custom_data=",
+ ffe.u.periodic.custom_len);
+ printaddr(ptr_to_kulong(ffe.u.periodic.custom_data));
+ tprints("}");
+ break;
+ case FF_RUMBLE:
+ tprintf(", rumble={strong_magnitude=%" PRIu16
+ ", weak_magnitude=%" PRIu16 "}",
+ ffe.u.rumble.strong_magnitude,
+ ffe.u.rumble.weak_magnitude);
+ break;
+ default:
+ break;
}
tprints("}");
@@ -121,10 +121,10 @@ MPERS_PRINTER_DECL(int, evdev_write_ioctl_mpers, struct tcb *const tcp,
const unsigned int code, const kernel_ulong_t arg)
{
switch (code) {
- case EVIOCSFF:
- return ff_effect_ioctl(tcp, arg);
- default:
- return RVAL_DECODED;
+ case EVIOCSFF:
+ return ff_effect_ioctl(tcp, arg);
+ default:
+ return RVAL_DECODED;
}
}
--
2.1.4