From 8e033aab6040f3d1f9e7c7cfc269204abfc81375 Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Sun, 13 Oct 2019 17:13:52 +0200 Subject: [PATCH] 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. --- evdev.c | 227 +++++++++++++++++++++++++------------------------- evdev_mpers.c | 86 +++++++++---------- 2 files changed, 156 insertions(+), 157 deletions(-) diff --git a/evdev.c b/evdev.c index f5c24ab7..e2a2a8b3 100644 --- a/evdev.c +++ b/evdev.c @@ -259,47 +259,47 @@ 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_???"); - case EV_KEY: - return decode_bitset(tcp, arg, evdev_keycode, - KEY_MAX, "KEY_???"); - case EV_REL: - return decode_bitset(tcp, arg, evdev_relative_axes, - REL_MAX, "REL_???"); - case EV_ABS: - return decode_bitset(tcp, arg, evdev_abs, - ABS_MAX, "ABS_???"); - case EV_MSC: - return decode_bitset(tcp, arg, evdev_misc, - MSC_MAX, "MSC_???"); - case EV_SW: - return decode_bitset(tcp, arg, evdev_switch, - SW_MAX, "SW_???"); - case EV_LED: - return decode_bitset(tcp, arg, evdev_leds, - LED_MAX, "LED_???"); - case EV_SND: - return decode_bitset(tcp, arg, evdev_snd, - SND_MAX, "SND_???"); - case EV_REP: - return decode_bitset(tcp, arg, evdev_autorepeat, - REP_MAX, "REP_???"); - case EV_FF: - return decode_bitset(tcp, arg, evdev_ff_types, - FF_MAX, "FF_???"); - 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_???"); - default: - tprints(", "); - printaddr(arg); - return RVAL_IOCTL_DECODED; + case 0: + return decode_bitset(tcp, arg, evdev_ev, + EV_MAX, "EV_???"); + case EV_KEY: + return decode_bitset(tcp, arg, evdev_keycode, + KEY_MAX, "KEY_???"); + case EV_REL: + return decode_bitset(tcp, arg, evdev_relative_axes, + REL_MAX, "REL_???"); + case EV_ABS: + return decode_bitset(tcp, arg, evdev_abs, + ABS_MAX, "ABS_???"); + case EV_MSC: + return decode_bitset(tcp, arg, evdev_misc, + MSC_MAX, "MSC_???"); + case EV_SW: + return decode_bitset(tcp, arg, evdev_switch, + SW_MAX, "SW_???"); + case EV_LED: + return decode_bitset(tcp, arg, evdev_leds, + LED_MAX, "LED_???"); + case EV_SND: + return decode_bitset(tcp, arg, evdev_snd, + SND_MAX, "SND_???"); + case EV_REP: + return decode_bitset(tcp, arg, evdev_autorepeat, + REP_MAX, "REP_???"); + case EV_FF: + return decode_bitset(tcp, arg, evdev_ff_types, + FF_MAX, "FF_???"); + 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_???"); + default: + tprints(", "); + printaddr(arg); + return RVAL_IOCTL_DECODED; } } @@ -309,62 +309,62 @@ 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_???"); + case _IOC_NR(EVIOCGPROP(0)): + return decode_bitset(tcp, arg, evdev_prop, + INPUT_PROP_MAX, "PROP_???"); # endif - case _IOC_NR(EVIOCGSND(0)): - return decode_bitset(tcp, arg, evdev_snd, - SND_MAX, "SND_???"); + case _IOC_NR(EVIOCGSND(0)): + return decode_bitset(tcp, arg, evdev_snd, + SND_MAX, "SND_???"); # ifdef EVIOCGSW - case _IOC_NR(EVIOCGSW(0)): - return decode_bitset(tcp, arg, evdev_switch, - SW_MAX, "SW_???"); + case _IOC_NR(EVIOCGSW(0)): + return decode_bitset(tcp, arg, evdev_switch, + SW_MAX, "SW_???"); # endif - case _IOC_NR(EVIOCGKEY(0)): - return decode_bitset(tcp, arg, evdev_keycode, - KEY_MAX, "KEY_???"); - case _IOC_NR(EVIOCGLED(0)): - return decode_bitset(tcp, arg, evdev_leds, - LED_MAX, "LED_???"); + case _IOC_NR(EVIOCGKEY(0)): + return decode_bitset(tcp, arg, evdev_keycode, + KEY_MAX, "KEY_???"); + case _IOC_NR(EVIOCGLED(0)): + return decode_bitset(tcp, arg, evdev_leds, + LED_MAX, "LED_???"); } /* multi-number fixed-length commands */ @@ -385,38 +385,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); @@ -435,14 +434,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 ff99544b..ebf9658b 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.40.0